HikariCP不使用Spring Boot的application.properties中的设置

时间:2017-06-02 22:12:00

标签: spring-boot hikaricp

我使用的是Spring Boot 1.5.3,我在 application.properties 中为HikariCP添加了以下设置:

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

但是一旦我启动Spring Boot,pool-name和minimum-idle的值就不同了:

[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"

1 个答案:

答案 0 :(得分:-1)

你配置了你的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());
}

}