2017-12-18 6 views
0

heroku 무료 계정에 Spring 부트 응용 프로그램을 배포하는 방법을 배우고 있습니다. 진짜 Postgres 데이터베이스를 Heroku의 가능한 애드온 중 하나로서 사용하기 전까지는 모든 것이 잘됩니다. 애드온을 추가하고 DB에 연결하기위한 모든 설정을 가져올 수 있지만 JpaRepositories 및 Pojos를 db에 매핑 할 때 데이터베이스를 만들 수 없습니다.Heroku Postgres with Spring boot JPA가 작동하지 않습니다.

My Heroku 대시 보드는 DB에 액세스하기위한 모든 자격 증명을 제공하며, Heroku가 주기적으로 환경 변수를 사용하여이를 대체하더라도 내 봄 부팅 응용 프로그램에서 사용합니다.

다음

application.properties : 나는 Heroku가 환경 변수를 사용하여 데이터 소스의 데이터를 무시합니다 읽었습니다하더라도

spring.jpa.hibernate.ddl-auto=create-drop 
spring.datasource.url=jdbc:postgres://xxxxxxxx:xxxxxx 
spring.datasource.username=xxxxxxxx 
spring.datasource.password=xxxxxxxx 

. 여기

package com.quicktutorialz.learnmicroservices.DemoHeroku.entities; 

import lombok.AllArgsConstructor; 
import lombok.Getter; 
import lombok.NoArgsConstructor; 
import lombok.Setter; 
import org.hibernate.validator.constraints.NotBlank; 

import javax.persistence.*; 

@Entity @Table(name="authors") @AllArgsConstructor @NoArgsConstructor 
@Getter @Setter 
public class Author { 

    @Id @Column(name="ID") @GeneratedValue 
    private Integer id; 
    @Column(name="NAME") @NotBlank 
    private String name; 
    @Column(name="EMAIL") @NotBlank 
    private String email; 
} 

내 제 POJO : 여기서

package com.quicktutorialz.learnmicroservices.DemoHeroku; 

import com.quicktutorialz.learnmicroservices.DemoHeroku.daos.AuthorDao; 
import com.quicktutorialz.learnmicroservices.DemoHeroku.daos.BookDao; 
import com.quicktutorialz.learnmicroservices.DemoHeroku.entities.Author; 
import com.quicktutorialz.learnmicroservices.DemoHeroku.entities.Book; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.web.bind.annotation.PathVariable; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RestController; 

import javax.annotation.PostConstruct; 
import javax.validation.Valid; 
import java.util.List; 

@RestController 
@SpringBootApplication 
public class DemoHerokuApplication { 

public static void main(String[] args) { 
    SpringApplication.run(DemoHerokuApplication.class, args); 
} 

@Autowired AuthorDao authorDao; 
@Autowired BookDao bookDao; 

@RequestMapping("/") 
public String hello(){ 
    return "Hello!"; 
} 

@RequestMapping("/books") 
public List<Book> getBooks(){ 
    return bookDao.findAll(); 
} 

@RequestMapping("/books/{id}") 
public Book getOneBook(@PathVariable(name = "id") Integer id){ 
    return bookDao.findOne(id); 
} 

@RequestMapping("/authors") 
public List<Author> getAuthors(){ 
    return authorDao.findAll(); 
} 

@RequestMapping("/authors/{id}") 
public Author getOneAuthor(@PathVariable(name = "id") Integer id){ 
    return authorDao.findOne(id); 
} 

@RequestMapping("/books/save") 
public Book saveBook(@Valid Book book){ 
    return bookDao.save(book); 
} 

@RequestMapping("/books/delete/{id}") 
public List<Book> deleteBook(@PathVariable(name = "id") Integer id){ 
    bookDao.delete(id); 
    return bookDao.findAll(); 
} 

@RequestMapping("/authors/save") 
public Author saveAuthor(@Valid Author author){ 
    return authorDao.save(author); 
} 

@RequestMapping("/authors/delete/{id}") 
public List<Author> deleteAuthor(@PathVariable(name = "id") Integer id){ 
    authorDao.delete(id); 
    return authorDao.findAll(); 
} 

@PostConstruct 
private void fillDatabase(){ 
    authorDao.save(new Author(null, "Gino Camarda", "[email protected]")); 
    authorDao.save(new Author(null, "Attilia Nomeldini", "[email protected]")); 

    bookDao.save(new Book(null, "Il basket per me", "Saggio sportivo", null, 1)); 
    bookDao.save(new Book(null, "W il basket", "Saggio sportivo", null, 1)); 

    bookDao.save(new Book(null, "Giornali e pareri", "Saggio giornalistico", null, 2)); 
    bookDao.save(new Book(null, "Versioni della verita", "Saggio giornalistico", null, 2)); 

} 
} 

처음으로 POJO :

package com.quicktutorialz.learnmicroservices.DemoHeroku.entities; 

import lombok.AllArgsConstructor; 
import lombok.Getter; 
import lombok.NoArgsConstructor; 
import lombok.Setter; 
import org.hibernate.validator.constraints.NotBlank; 

import javax.persistence.*; 
import javax.validation.constraints.NotNull; 
import java.util.Date; 

@Entity @Table(name="books") 
@AllArgsConstructor @NoArgsConstructor @Getter @Setter 
public class Book { 
    @Id @Column(name="ID") @GeneratedValue 
    private Integer id; 
    @Column(name="TITLE") @NotBlank 
    private String title; 
    @Column(name="TITLE") @NotBlank 
    private String description; 
    @Column(name="TITLE") 
    private Date dateOfRelease; 
    @Column(name="TITLE") @NotNull 
    private int authorId; 

    @PrePersist 
    private void setDate(){ 
    this.dateOfRelease = new Date(); 
    } 
} 
여기

여기
<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>com.quicktutorialz.learnmicroservices</groupId> 
<artifactId>DemoHeroku</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>jar</packaging> 

<name>DemoHeroku</name> 
<description>Demo project for Spring Boot</description> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.9.RELEASE</version> 
    <relativePath/> <!-- lookup parent from repository --> 
</parent> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.postgresql</groupId> 
     <artifactId>postgresql</artifactId> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.projectlombok</groupId> 
     <artifactId>lombok</artifactId> 
     <optional>true</optional> 
     <version>1.16.10</version> <!-- added --> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
</build> 
</project> 

내 컨트롤러 내 pom.xml 파일이며

그리고 이것들은 JpaRepositories입니다.

AuthorDao.java :

package com.quicktutorialz.learnmicroservices.DemoHeroku.daos; 

import com.quicktutorialz.learnmicroservices.DemoHeroku.entities.Author; 
import org.springframework.data.jpa.repository.JpaRepository; 

public interface AuthorDao extends JpaRepository<Author, Integer>{ 

} 

BookDao.java

package com.quicktutorialz.learnmicroservices.DemoHeroku.daos; 

import com.quicktutorialz.learnmicroservices.DemoHeroku.entities.Book; 
import org.springframework.data.jpa.repository.JpaRepository; 

public interface BookDao extends JpaRepository<Book, Integer>{ 
} 

내가 로컬 메이븐 함께 포장 할 때이 오류가 얻을 : I 배포

Description: 

Cannot determine embedded database driver class for database type NONE 

을 Heroku에서 내 앱이 일반적인 오류로 인해 충돌 함 :

at=error code=H10 desc="App crashed" method=GET path="/" 
+0

나는 즉시 제거 –

답변

0

문제는 Book pojo의 @Column 주석에 대한 과거 사본 때문에 발생했습니다. 정확히 같은 이름의 열이있었습니다!

관련 문제