如何在Spring Roo设置中连接PostgreSQL?

时间:2016-12-15 21:16:45

标签: postgresql spring-roo

我正在使用spring.io/spring-roo/#running-from-shell快速指南的脚本,一个10行示例。

唯一的修改是jpa setup --provider行,更改为连接PostgreSQL(HIBERNATE --database POSTGRES)。所有步骤和代码均位于this roo_hello2pg.md github document

application.properties似乎

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc\:postgresql\://localhost\:5432/hello2bd
spring.datasource.username=postgres
spring.datasource.password=postgres

我还需要什么?一些spring.jpa.hibernate行?浏览器生成错误" status = 500"使用数据库时(插入一个值)。

1 个答案:

答案 0 :(得分:3)

正如我在gitHub存储库中看到的那样,您已正确配置了与Postgres数据库的连接。

但您是否在系统中创建了hello2db数据库和Timer表?

作为Spring Boot文档,如果您使用嵌入式数据库(H2,HSQL或Derby),JPA数据库将自动创建

检查http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-creating-and-dropping-jpa-databases

在您的情况下,要使用Postgres DB自动创建数据库,您应该在spring.jpa.hibernate.ddl-auto=create-drop文件中包含application.properties属性。

希望它有所帮助,