Java.HikariCP.Where do you typically define HikariCP settings in a Spring Boot project?

In a Spring Boot project, you typically define HikariCP settings in the application.properties or application.yml file. Spring Boot auto-configures HikariCP as the default connection pool if it’s on the classpath, and you can customize it by adding properties with the prefix spring.datasource.hikari.*.

For example, in application.properties:

spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=postgres
spring.datasource.password=secret

spring.datasource.hikari.maximum-pool-size=20
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.connection-timeout=20000
spring.datasource.hikari.leak-detection-threshold=15000

Or in application.yml:

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/mydb
    username: postgres
    password: secret
    hikari:
      maximum-pool-size: 20
      minimum-idle: 5
      idle-timeout: 30000
      connection-timeout: 20000
      leak-detection-threshold: 15000

Alternatively, you can programmatically configure HikariCP by defining a DataSource bean in a @Configuration class using HikariDataSource

This entry was posted in Без рубрики. Bookmark the permalink.