9

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?

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
SheppardDigital
  • 3,165
  • 8
  • 44
  • 74

2 Answers2

7

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.

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • 6
    This is true, but only for autoconfiguration. Also, spring.datasource.hikari.maximum-pool-size=20, should works. – Mr. Mars Oct 19 '19 at 17:13
7

In case of multiple datasources and because you are using DataSourceBuilder the following works.

spring.datasource.maximum-pool-size=20
trwbi.datasource.maximum-pool-size=20

Also in your case I would recommend to turn off autoconfiguration:

@SpringBootApplication(scanBasePackages = {...},
        exclude = {DataSourceAutoConfiguration.class} )
@EnableSwagger2
public class Application {
....

If you don't use builder, but use autoconfiguration, then use

spring.datasource.hikari.minimumIdle=1
spring.datasource.hikari.maximum-pool-size=3
Omar
  • 101
  • 2