2016-12-15 50 views
3

我正在使用spring.io/spring-roo/#running-from-shell快速指南的腳本,一個10行的示例。如何在Spring Roo安裝程序中連接PostgreSQL?

唯一的修改是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」。

+0

您的問題,並添加**完整**錯誤消息(理想情況下與異常的堆棧跟蹤)。 [_Formatted_](http://stackoverflow.com/help/formatting)文本請[無屏幕截圖](http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images問題/ 285557#285557) –

+0

嗨@a_horse_with_no_name,我在git中包含所有生成的文件,請參閱[application.properties](https://github.com/ ppKrauss/dummy-java-spring/blob/master/hello2pg/src/main/resources/application.properties)等等......對於錯誤消息抱歉,只有在辦公室的tomorow,瀏覽器中狀態爲500,Maven編譯。 –

+0

請描述您的環境:Roo版本,JDK版本,S.O,...以及拋出的錯誤。 – eruiz

回答

3

正如我在你的gitHub倉庫中看到的,你已經正確地配置了到Postgres數據庫的連接。

但是,您是否在您的系統中創建了hello2db數據庫表和Timer表?

隨着春季啓動文檔最高審計機關,JPA數據庫將自動創建只有如果您使用嵌入式數據庫(H2,HSQL或Derby)

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

在你的情況下,以創建數據庫自動使用Postgres DB,則應在application.properties文件中包含spring.jpa.hibernate.ddl-auto=create-drop屬性。

希望它有幫助,

+1

謝謝! 'spring.jpa.hibernate.ddl-auto = create-drop'這一行do de magic! –

相關問題