Search code examples
spring-bootproperties-filehikaricp

Hikari - Spring Boot is ignoring hikari properties


I have a Spring Boot 2 application which has two datasources. Both datasources work, however I am unable to change properties such as maximum-pool-size, my changes are not taking effect.

I am configuration my two datasources in my application.properties file;

spring.datasource.url=jdbc:sqlserver://server;databaseName=ProductionMetrics
spring.datasource.username=ProductionMeusernametricsUser
spring.datasource.password=password
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.hikari.maximum-pool-size=20

# Products
trwbi.datasource.url=jdbc:sqlserver://server;databaseName=TRWBI
trwbi.datasource.username=username
trwbi.datasource.password=password
trwbi.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
trwbi.datasource.hikari.maximum-pool-size=20

Then, I'm setting up the two datasources like this;

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
        entityManagerFactoryRef = "defaultEntityManagerFactory",
        transactionManagerRef = "defaultTransactionManager",
        basePackages = {
                "com.domain.visualisation.shared.repository"
        }
)
public class DefaultDbConfig {

    @Primary
    @Bean(name = "defaultDataSource")
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource defaultDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Primary
    @Bean(name = "defaultEntityManagerFactory")
    public LocalContainerEntityManagerFactoryBean
    entityManagerFactory(
            EntityManagerFactoryBuilder builder,
            @Qualifier("defaultDataSource") DataSource dataSource
    ) {
        return builder
                .dataSource(dataSource)
                .packages("com.domain.visualisation.shared.entities")
                .persistenceUnit("default")
                .build();
    }

    @Primary
    @Bean(name = "defaultTransactionManager")
    public PlatformTransactionManager defaultTransactionManager(
            @Qualifier("defaultEntityManagerFactory") EntityManagerFactory defaultEntityManagerFactory
    ) {
        return new JpaTransactionManager(defaultEntityManagerFactory);
    }
}

When I turn on debugging for Hikari, I can see that the maximumPoolSize value is still 10, rather than the value of 20 that I have defined. I've tried to apply other properties such as leak-detection-threshhold, pool-name and idle-timeout, but neither of those are being applied either.

Why are they not being applied?


Solution

  • You should use property name maximumPoolSize

    spring.datasource.hikari.maximumPoolSize=20
    

    maximumPoolSize This property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections.