How to configure postgres data base in a spring boot application

There are 2 steps involved in configuring postgres sql data base to a spring boot application assuming we already have data base setup.

  1. Add postgres sql dependency to pom.xml.

postgres_pom

2. We need to tell Spring container to look into postgres by changing the application.properties.

application.properties

So the list of possible options for ddl-auto are

  • validate: validate the schema, makes no changes to the database.
  • update: update the schema.
  • create: creates the schema, destroying previous data.
  • create-drop: drop the schema when the SessionFactory is closed explicitly, typically when the application is stopped.

I added spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true as the server is throwing following warning while startup.

java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc42.Jdbc42Connection.createClob() is not yet implemented.

Now restart server and you should see successful db connection logs. When the connection is successful spring container tries to validate the entities in the project to the db tables.

Happy coding!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.