I'm using spring boot version 1.5.2 and I have a use case where I need to configure 2 data sources in an application. I have been successful in getting the app to connect to 2 databases, however I'm not able to set connection pool properties for them.
Here's the configuration class:
@Configuration
public class DataSourceConfig {
@Bean(name = "oneDataSource")
@ConfigurationProperties(prefix = "spring.datasource.one")
@Primary
public DataSource oneDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "twoDataSource")
@ConfigurationProperties(prefix = "spring.datasource.two")
public DataSource twoDataSource() {
return DataSourceBuilder.create().build();
}
}
On debugging DataSourceBuilder, I can see that it is instantiating beans of type org.apache.tomcat.jdbc.pool.DataSource, which is what I want, however the poolProperties field in the DataSource object always contains some default properties and not what I intended.
Here's my application.yml:
spring:
profiles: dev
datasource:
one:
url: jdbc:mariadb://localhost:3306/one
username: user1
password: password
driverClassName: org.mariadb.jdbc.Driver
initialize: true
tomcat:
testOnBorrow: true
validation-query: SELECT 1
testWhileIdle: true
continueOnError: true
initialSize: 2
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 5000
minIdle: 2
maxIdle: 3
maxActive: 30
two:
url: jdbc:mariadb://localhost:3306/two
username: user1
password: password
driverClassName: org.mariadb.jdbc.Driver
initialize: true
tomcat:
testOnBorrow: true
validation-query: SELECT 1
testWhileIdle: true
continueOnError: true
initialSize: 2
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 5000
minIdle: 2
maxIdle: 3
maxActive: 30
Am I missing something? Is DataSourceBuilder even capable of looking for the pool properties configured this way? What would be the best way to configure 2 data sources with my desired pool properties?