Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect PostgreSQL in a Spring Roo setup?

I am using the script of the spring.io/spring-roo/#running-from-shell fast guide, a 10 lines example.

The only modification is the jpa setup --provider line, changed to connect PostgreSQL (HIBERNATE --database POSTGRES). All the steps and code are at this roo_hello2pg.md github document.

The application.properties seems

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

What more I need? Some spring.jpa.hibernate lines? The browser generates error "status=500" when use database (insert a value).

like image 205
Peter Krauss Avatar asked Jan 26 '26 17:01

Peter Krauss


1 Answers

As I could see in your gitHub repository, you have configured your connection to the Postgres database correctly.

But did you create the hello2db database and the Timer table in your system?

As the Spring Boot documentation sais, JPA databases will be automatically created only if you use an embedded database (H2, HSQL or Derby)

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

In your case, to create the database automatically using a Postgres DB, you should include the spring.jpa.hibernate.ddl-auto=create-drop property in the application.properties file.

Hope it helps,

like image 129
jcgarcia Avatar answered Jan 29 '26 12:01

jcgarcia