Spring Boot provides extensive support for relational databases through multiple abstraction layers, from direct JDBC access usingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/spring-projects/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
JdbcTemplate or JdbcClient up to full object-relational mapping with Hibernate and Spring Data JPA. Auto-configuration handles DataSource setup, connection pooling, schema migration, and repository scanning so you can focus on your domain model rather than infrastructure plumbing.
DataSource auto-configuration
DataSource configuration is controlled by external configuration properties inspring.datasource.*. At a minimum, provide the JDBC URL:
application.yaml
- HikariCP — preferred for its performance and concurrency
- Tomcat pooling DataSource — used if HikariCP is not available
- Commons DBCP2 — used if Tomcat pool is not available
- Oracle UCP — used if none of the above are available
If you use
spring-boot-starter-jdbc or spring-boot-starter-data-jpa, you automatically get HikariCP as a dependency.Embedded databases
For development, Spring Boot can auto-configure embedded H2, HSQL, or Derby databases with no connection URL required:pom.xml
HikariCP configuration
Fine-tune the connection pool with HikariCP-specific properties:application.yaml
Lazy connections
Wrap the pooledDataSource in a proxy that fetches JDBC connections as late as possible:
application.yaml
JPA and Spring Data JPA
- JPA
- JDBC
The Repository interface:Spring Data JPA generates the SQL for standard finder methods from the method name. For complex queries, use the
spring-boot-starter-data-jpa starter pulls in Hibernate, Spring Data JPA, and Spring ORM. Define your entity classes and repositories, and Spring Boot handles the rest.Entity class:City.java
CityRepository.java
@Query annotation.Configure DDL behavior:application.yaml
Schema migration
Flyway
Flyway
Flyway manages database schema migrations through versioned SQL scripts. Add Place migration scripts in Flyway auto-configures when it detects the dependency on the classpath and runs migrations on startup.
spring-boot-starter-data-jpa (or spring-jdbc) and the flyway-core dependency:pom.xml
src/main/resources/db/migration/ following the naming convention V{version}__{description}.sql:Liquibase
Liquibase
Liquibase manages schema changes through XML, YAML, JSON, or SQL changelogs. Add the dependency:By default, Liquibase reads
pom.xml
classpath:/db/changelog/db.changelog-master.yaml. Configure a custom path:application.yaml
jOOQ
jOOQ Object Oriented Querying generates Java code from your database schema and lets you build type-safe SQL queries through its fluent API. Spring Boot auto-configures aDSLContext bean and connects it to your DataSource:
MyBean.java
R2DBC (reactive SQL)
For reactive applications, use R2DBC to connect to relational databases without blocking:application.yaml
ReactiveCrudRepository:
CityRepository.java
H2 web console
The H2 database provides a browser-based console that Spring Boot can auto-configure for you when using Spring Boot DevTools. Enable it manually with:application.yaml