使用Postgres调试spring boot数据jpa app

时间:2015-11-18 12:58:04

标签: java spring hibernate postgresql jpa

我正在Spring Boot和Postgres上构建应用程序,我已经设置了所有内容,但是数据不是从实体到JpaRepository到RestAPI,运行应用程序时没有错误或警告,所以我不明白怎么能我发现发生了什么事?

这是我的档案:

application.properties文件

spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/dbname
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.properties.hibernate.default_schema=public

申请文件:

@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan(basePackages = "com.springapp.app")
@EnableJpaRepositories("com.springapp.app.repository")
@EntityScan("com.springapp.app.models")
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

实体档案:

@Entity
@Table(name = "press")
public class PressEntity {
    @Id @GeneratedValue
    @Column(name = "id")
    private int id;

    @Column(name = "sort_id")
    private int sortId;

    @Column(name = "logo")
    private String logo;

    @Column(name = "description")
    private String description;

    @Column(name = "link")
    private String link;

    @Column(name = "link_text")
    private String linkText;

    public PressEntity() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getSortId() {
        return sortId;
    }

    public void setSortId(int sortId) {
        this.sortId = sortId;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public String getLinkText() {
        return linkText;
    }

    public void setLinkText(String linkText) {
        this.linkText = linkText;
    }
}

存储库文件:

@Repository
public interface PressRepository extends JpaRepository<PressEntity, Long> {
}
编辑:我正在基于这个项目构建它:

https://github.com/bkielczewski/example-spring-boot-rest/tree/master/src/main/java/eu/kielczewski/example

0 个答案:

没有答案