← All posts

Spring Boot + PostgreSQL

Getting a Spring Boot app talking to PostgreSQL is easy. Here’s all you need.

Step 0 — Make sure you have JPA in your pom.xml

Start with the JPA starter:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-jpa</artifactId>  </dependency>

Step 1 — Add PostgreSQL to your pom.xml

Then add the PostgreSQL driver:

<!-- PostgreSQL -->
<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <scope>runtime</scope>
</dependency>

Step 2 — Configure your application.yaml

Last, point Spring at your database:

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/my-awesome-app
    username: my-postgres-username
    password: my-postgres-password
  jpa:
    hibernate:
      ddl-auto: update

That’s it! Easy?