HikariDataSource is the javax.sql.DataSource implementation of HikariCP, a JDBC connection pool. It keeps a set of open database connections, lends them to your code on demand and takes them back when your code closes them, which avoids the cost of opening a new connection for every query. It is the default pool in Spring Boot.
In Spring Boot you usually never create it by hand. When HikariCP is on the classpath, auto-configuration builds a HikariDataSource from the spring.datasource.* and spring.datasource.hikari.* properties.
com.zaxxer.hikari.HikariDataSource extends HikariConfig and implements DataSource and Closeable. Calling getConnection() returns a proxy Connection. When your code calls close() on that proxy, the physical connection is returned to the pool instead of being closed.
The pool handles several jobs for you:
Because it is thread-safe, one HikariDataSource instance is shared by the whole application.
DataSourceAutoConfiguration chooses the first available pool in this order: HikariCP, Tomcat JDBC, Commons DBCP2, then Oracle UCP. The spring-boot-starter-jdbc and spring-boot-starter-data-jpa starters both bring in HikariCP, so you get it without extra dependencies. To force another pool, set spring.datasource.type.
Pool settings live under spring.datasource.hikari:
| Property | Purpose | Default |
|---|---|---|
maximum-pool-size | Maximum connections, idle and in use | 10 |
minimum-idle | Idle connections kept ready | Same as the maximum |
connection-timeout | Longest wait for a connection, in milliseconds | 30000 |
idle-timeout | How long an idle connection may stay in a pool larger than minimum-idle, in milliseconds | 600000 |
max-lifetime | Maximum age of a connection, in milliseconds | 1800000 |
leak-detection-threshold | Logs a warning when a connection is held longer than this | 0 (disabled) |
Set max-lifetime a few seconds to minutes below any limit imposed by the database or a network device, so the pool retires a connection before something else kills it silently.
A larger pool is not faster. A pool of about 10 connections serves many hundreds of concurrent requests when queries are short, because most threads wait on CPU or network rather than on the database. The HikariCP project recommends starting small and increasing only when metrics show threads waiting for connections. Remember that the sum of all application instances must stay below the database server's connection limit.
Define your own bean when you need a second database or full control. Boot's auto-configuration backs off when a DataSource bean exists.
With multiple data sources, bind properties through @ConfigurationProperties on a HikariDataSource bean and mark one as @Primary.
Always release connections. JdbcTemplate, Spring Data and JPA do this for you. With raw JDBC use try-with-resources:
Avoid holding a transaction, and therefore a connection, while calling slow external services. If many threads time out with Connection is not available, request timed out after 30000ms, the pool is exhausted, usually because of leaked connections or long transactions. Turn on leak-detection-threshold to find the code that holds them.
With Micrometer and Actuator, Boot publishes hikaricp.connections.active, hikaricp.connections.idle, hikaricp.connections.pending and hikaricp.connections.timeout. Watch pending and timeout counts to know whether the pool is undersized or connections are leaking.
Yes. Since Spring Boot 2.0 it is the default pool, replacing Tomcat JDBC, and it remains so in Spring Boot 3.
Spring closes it on shutdown when it is a bean. In plain Java code, call close() or use try-with-resources so the pool releases its connections.
HikariCP recommends leaving minimum-idle unset so it behaves as a fixed-size pool, which gives the best response to spikes. Lower it only if you need to shrink during quiet periods.
Yes, but the pool size still limits concurrent database work. With virtual threads, many tasks may wait for a connection, so keep the pool sized to what the database can handle.
HikariDataSource is a fast, thread-safe JDBC connection pool and the default in Spring Boot. Configure it through spring.datasource.hikari.*, keep the maximum pool size modest, set max-lifetime below database and network limits, and watch the hikaricp.* metrics. Close connections promptly and avoid long transactions so the pool never runs dry.