1

I am using Spring Boot 1.5.3 and I added the following settings for HikariCP in the application.properties:

spring.datasource.hikari.data-source-properties.prepStmtCacheSize=250
spring.datasource.hikari.data-source-properties.prepStmtCacheSqlLimit=2048
spring.datasource.hikari.data-source-properties.cachePrepStmts=true
spring.datasource.hikari.data-source-properties.useServerPrepStmts=true

spring.datasource.hikari.minimum-idle=7
spring.datasource.hikari.pool-name=Test-1

But once I start Spring Boot, the values of pool-name and minimum-idle are different :

[DEBUG]  HikariConfig - jdbcUrl........................."jdbc:mysql://localhost:3306/test?autoReconnect=true"
[DEBUG]  HikariConfig - leakDetectionThreshold..........0
[DEBUG]  HikariConfig - maxLifetime.....................1800000
[DEBUG]  HikariConfig - maximumPoolSize.................10
[DEBUG]  HikariConfig - metricRegistry..................none
[DEBUG]  HikariConfig - metricsTrackerFactory...........none
[DEBUG]  HikariConfig - minimumIdle.....................10
[DEBUG]  HikariConfig - password........................<masked>
[DEBUG]  HikariConfig - poolName........................"HikariPool-1"
ThomasW
  • 481
  • 1
  • 6
  • 12

1 Answers1

4

Did you configure your Bean?:

@Configuration
public class HikariCPConfig {

@Bean
@ConfigurationProperties(prefix = "spring.datasource.hikari")
public HikariConfig hikariConfig() {
    return new HikariConfig();
}

@Bean
public DataSource dataSource() {
    return new HikariDataSource(hikariConfig());
}

}

ian1095
  • 551
  • 4
  • 8
  • Thank you ! I thought I don't need to specify the HikariConfig bean. However after adding this bean, I had to remove the spring.datasource.url, spring.datasource.username, spring.datasource.password from my application.properties and to use spring.datasource.hikari.jdbc-url, spring.datasource.hikari.username and spring.datasource.password instead. – ThomasW Jun 03 '17 at 07:36
  • Thats correct make sure you also add the property: datasource.hikari.driverClassName=com.mysql.jdbc.Driver – ian1095 Jun 03 '17 at 12:18
  • 1
    There should be no need for either of the beans shown here. Spring Boot will auto-configure Hikari for you using the settings in application.properties. – Andy Wilkinson Jun 03 '17 at 12:20
  • 1
    You are absolutely right, @Andy ! I forgot to mention that I have two datasources which causes my problem. I would be glad if you could check whether my workaround is the best way of handling my issue :[new question](https://stackoverflow.com/q/44373186/6595261) – ThomasW Jun 05 '17 at 16:19
  • 2
    @AndyWilkinson Somebody please, build this man's statue. Thanks alot. – amira Dec 17 '19 at 13:24
  • Thank you @ian1095 I had the dataSource bean created but did not add @ConfigurationProperties(prefix = "spring.datasource.hikari") hence it was not pulling the Hikari properties from property file in my case. – Ashish Singh Oct 07 '22 at 14:27