Spring Boot Connection Pool Auto-Configuration
Fast recall
Quick revision
Core answer
Whether you know Spring Boot auto-configures HikariCP from properties.
Manually creating a DataSource bean when auto-config already does it.
Mention spring.datasource.hikari.* for pool tuning and that HikariCP is the default.
Interview-ready guide
Interview answer
With starter-jdbc and Hikari on the classpath, Boot commonly builds HikariDataSource from spring.datasource.url, username, and password. Defining a DataSource bean makes auto-configuration back off. An embedded database can be configured with fewer explicit settings. Hikari's defaults are library defaults, not workload-aware tuning performed by Boot.
Spring Boot Connection Pool Auto-Configuration
Direct Answer
When JDBC/DataSource classes are present, no user DataSource bean exists, and configuration can supply a database connection, Spring Boot can auto-configure a DataSource. It prefers supported pooling implementations found on the classpath, commonly HikariCP. Boot binds properties and applies defaults; it does not automatically tune the pool to the workload or database capacity.
Code Example
# application.properties — Spring builds a HikariCP DataSource from this
spring.datasource.url=jdbc:mysql://localhost:3306/shop
spring.datasource.username=app
spring.datasource.password=secret
# optional pool tuning (HikariCP)
spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.idle-timeout=600000
@Service
class UserService {
private final JdbcTemplate jdbc; // uses the auto-configured DataSource
UserService(JdbcTemplate jdbc) { this.jdbc = jdbc; }
}
Common Mistakes & Pitfalls
- Hand-writing a DataSource bean: usually unnecessary — auto-config handles it.
- Adding another pool dependency: HikariCP is already the default.
- Forgetting required properties: no URL/credentials → startup fails.
- Tuning the wrong prefix: pool settings go under
spring.datasource.hikari.*.
Check your understanding
Answer these without looking back at the article.
- What is connection pooling and why is it critical for production Java applications?
- What is HikariCP and how do you configure it in Spring Boot?
- What happens when all connections in a pool are in use?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.