简体   繁体   中英

How do I configure HikariCP in mySpringBoot application.yml?

I have been trying to configure couple of HikariCP properties in my yaml as below,

datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    hikari:
        maximum-pool-size: 20
        leakDetectionThreshold: 60000 # 60 seconds

When I start my service with Hikari debug enabled, I see it does not seem to pick the changes,

2020-06-17 17:47:54,144 [DEBUG] ( 1)              HikariConfig:1020  HikariPool-1 - configuration:
2020-06-17 17:47:54,147 [DEBUG] ( 1)              HikariConfig:1052  allowPoolSuspension.............false
2020-06-17 17:47:54,147 [DEBUG] ( 1)              HikariConfig:1052  autoCommit......................true
2020-06-17 17:47:54,147 [DEBUG] ( 1)              HikariConfig:1052  catalog.........................none
2020-06-17 17:47:54,147 [DEBUG] ( 1)              HikariConfig:1052  connectionInitSql...............none
2020-06-17 17:47:54,147 [DEBUG] ( 1)              HikariConfig:1052  connectionTestQuery.............none
2020-06-17 17:47:54,147 [DEBUG] ( 1)              HikariConfig:1052  connectionTimeout...............30000
2020-06-17 17:47:54,147 [DEBUG] ( 1)              HikariConfig:1052  dataSource......................none
2020-06-17 17:47:54,147 [DEBUG] ( 1)              HikariConfig:1052  dataSourceClassName.............none
2020-06-17 17:47:54,148 [DEBUG] ( 1)              HikariConfig:1052  dataSourceJNDI..................none
2020-06-17 17:47:54,148 [DEBUG] ( 1)              HikariConfig:1052  dataSourceProperties............{password=<masked>}
2020-06-17 17:47:54,150 [DEBUG] ( 1)              HikariConfig:1052  driverClassName................."com.mysql.cj.jdbc.Driver"
2020-06-17 17:47:54,151 [DEBUG] ( 1)              HikariConfig:1052  healthCheckProperties...........{}
2020-06-17 17:47:54,151 [DEBUG] ( 1)              HikariConfig:1052  healthCheckRegistry.............none
2020-06-17 17:47:54,151 [DEBUG] ( 1)              HikariConfig:1052  idleTimeout.....................600000
2020-06-17 17:47:54,151 [DEBUG] ( 1)              HikariConfig:1052  initializationFailTimeout.......1
2020-06-17 17:47:54,151 [DEBUG] ( 1)              HikariConfig:1052  isolateInternalQueries..........false
2020-06-17 17:47:54,151 [DEBUG] ( 1)              HikariConfig:1052  jdbcUrl.........................jdbc:mysql:replication://address=(type=master)(host=1.2.3.4),address=(type=master)(host=1.3.2.8)/test?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
2020-06-17 17:47:54,151 [DEBUG] ( 1)              HikariConfig:1052  leakDetectionThreshold..........0
2020-06-17 17:47:54,152 [DEBUG] ( 1)              HikariConfig:1052  maxLifetime.....................1800000
2020-06-17 17:47:54,152 [DEBUG] ( 1)              HikariConfig:1052  maximumPoolSize.................10
2020-06-17 17:47:54,152 [DEBUG] ( 1)              HikariConfig:1052  metricRegistry..................none
2020-06-17 17:47:54,152 [DEBUG] ( 1)              HikariConfig:1052  metricsTrackerFactory...........com.zaxxer.hikari.metrics.micrometer.MicrometerMetricsTrackerFactory@4d210648
2020-06-17 17:47:54,152 [DEBUG] ( 1)              HikariConfig:1052  minimumIdle.....................10
2020-06-17 17:47:54,152 [DEBUG] ( 1)              HikariConfig:1052  password........................<masked>
2020-06-17 17:47:54,152 [DEBUG] ( 1)              HikariConfig:1052  poolName........................"HikariPool-1"
2020-06-17 17:47:54,152 [DEBUG] ( 1)              HikariConfig:1052  readOnly........................false
2020-06-17 17:47:54,152 [DEBUG] ( 1)              HikariConfig:1052  registerMbeans..................false
2020-06-17 17:47:54,153 [DEBUG] ( 1)              HikariConfig:1052  scheduledExecutor...............none
2020-06-17 17:47:54,153 [DEBUG] ( 1)              HikariConfig:1052  schema..........................none
2020-06-17 17:47:54,153 [DEBUG] ( 1)              HikariConfig:1052  threadFactory...................internal
2020-06-17 17:47:54,153 [DEBUG] ( 1)              HikariConfig:1052  transactionIsolation............default
2020-06-17 17:47:54,153 [DEBUG] ( 1)              HikariConfig:1052  validationTimeout...............5000

Am I missing something?

In Spring Boot docs Hikari settings look like:

spring:
  datasource:
    hikari:
      driver-class-name: com.mysql.cj.jdbc.Driver
      maximum-pool-size: 20
      leakDetectionThreshold: 60000 # 60 seconds

Since you are using Spring boot, the correct format should be:

spring:
  datasource:
    hikari:
      driver-class-name: com.mysql.cj.jdbc.Driver
      maximum-pool-size: 20
      leak-detection-threshold: 10000

Actually using dash( leak-detection-threshold ) or camelCase( leakDetectionThreshold ) would be fine, better to make it consistant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM