This works for my boot application in case it helps. This class tells you what properties the config object is looking for:
I think multiple datasources could be supporting by adding datasource_whatever
to the property keys in the source config file. Cheers!
@Configuration
class DataSourceConfig {
@Value('${spring.datasource.username}')
private String user;
@Value('${spring.datasource.password}')
private String password;
@Value('${spring.datasource.url}')
private String dataSourceUrl;
@Value('${spring.datasource.dataSourceClassName}')
private String dataSourceClassName;
@Value('${spring.datasource.connectionTimeout}')
private int connectionTimeout;
@Value('${spring.datasource.maxLifetime}')
private int maxLifetime;
@Bean
public DataSource primaryDataSource() {
Properties dsProps = [url: dataSourceUrl, user: user, password: password]
Properties configProps = [
connectionTestQuery: 'select 1 from dual',
connectionTimeout: connectionTimeout,
dataSourceClassName: dataSourceClassName,
dataSourceProperties: dsProps,
maxLifetime: maxLifetime
]
// A default max pool size of 10 seems reasonable for now, so no need to configure for now.
HikariConfig hc = new HikariConfig(configProps)
HikariDataSource ds = new HikariDataSource(hc)
ds
}
}