Reputation: 3255
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?
Upvotes: 9
Views: 14892
Reputation: 101
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
Upvotes: 7
Reputation: 58772
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.
Upvotes: 7