For the Hikari connection pool configuration, we enable it by using spring.datasource.type and assigning it fully qualified name of the connection pool implementation in application.properties file as following.
spring.datasource.type = com.zaxxer.hikari.HikariDataSource
If we are using Spring Boot 2.0 and onwards, Spring Boot selects HikariDataSource by default and we need not to configure above line. Now to configure Hikari specific connection pool settings, Spring Boot provides spring.datasource.hikari.* prefix to be used in application.properties file. We will discuss here some frequently used configurations.
1. connectionTimeout
connectionTimeout is the maximum number of milliseconds that a client will wait for a connection from connection pool. We need to configure it as following.
spring.datasource.hikari.connection-timeout=20000
2. minimumIdle
minimumIdle is the minimum number of idle connections that is maintained by HikariCP in connection pool. It is configured as following.
spring.datasource.hikari.minimum-idle=5
3. maximumPoolSize
maximumPoolSize configures the maximum pool size. It is configured as following.
spring.datasource.hikari.maximum-pool-size=12
4. idleTimeout
idleTimeout is the maximum amount of time in milliseconds that a connection is allowed to sit idle in connection pool. It is configured as following.
spring.datasource.hikari.idle-timeout=300000
5. maxLifetime
maxLifetime is the maximum life time in milliseconds of a connection in pool after it is closed. It is configured as following.
spring.datasource.hikari.max-lifetime=1200000
An in-use connection will never be retired, only when it is closed will it then be removed after maximum lifetime.
6. autoCommit
autoCommit configures the default auto-commit behaviour of connections returned from pool. Default value is true.
spring.datasource.hikari.auto-commit=true