You have to provide the additional information by your own code.
Do not use DataSourceBuilder. Here is examples of Tomcat-Jdbc and Hikari
@Bean(name = "sourceBatchDataSource")
public DataSource sourceBatchDataSource() {
HikariDataSource hikariDataSource = new HikariDataSource();
hikariDataSource.setJdbcUrl(sourceDataSourceProperties.getUrl());
hikariDataSource.setUsername(sourceDataSourceProperties.getUsername());
hikariDataSource.setPassword(sourceDataSourceProperties.getPassword());
hikariDataSource.setDriverClassName(sourceDataSourceProperties.getDriverClassName());
hikariDataSource.setAutoCommit(from(environment.getProperty("spring.datasource.hikari.auto-commit")));
hikariDataSource.setConnectionTimeout(environment.getProperty("spring.datasource.hikari.connection-timeout", Integer.class));
hikariDataSource.setMaximumPoolSize(environment.getProperty("spring.datasource.hikari.maximum-pool-size", Integer.class));
hikariDataSource.setMaxLifetime(environment.getProperty("spring.datasource.hikari.max-lifetime", Integer.class));
hikariDataSource.setMinimumIdle(environment.getProperty("spring.datasource.hikari.minimum-idle", Integer.class));
hikariDataSource.setPoolName("SourceBatchHikariCP");
return hikariDataSource;
}
@Primary
@Bean(destroyMethod = "close", name = "sourceDataSource")
public DataSource sourceDataSource() {
DataSourceProperties dataSourceProperties = dataSourceProperties();
PoolProperties properties = new PoolProperties();
properties.setUrl(dataSourceProperties.getUrl());
properties.setDriverClassName(dataSourceProperties.getDriverClassName());
properties.setUsername(dataSourceProperties.getUsername());
properties.setPassword(dataSourceProperties.getPassword());
properties.setInitialSize(environment.getProperty("spring.datasource.tomcat.initial-size", Integer.class));
properties.setMaxWait(environment.getProperty("spring.datasource.tomcat.max-wait", Integer.class));
properties.setMaxActive(environment.getProperty("spring.datasource.tomcat.max-active", Integer.class));
properties.setMaxIdle(environment.getProperty("spring.datasource.tomcat.max-idle", Integer.class));
properties.setMinIdle(environment.getProperty("spring.datasource.tomcat.min-idle", Integer.class));
properties.setDefaultAutoCommit(from(environment.getProperty("spring.datasource.tomcat.default-auto-commit")));
properties.setValidationQuery(environment.getProperty("spring.datasource.tomcat.validation-query"));
properties.setTestOnBorrow(from(environment.getProperty("spring.datasource.tomcat.test-on-borrow")));
properties.setTestWhileIdle(from(environment.getProperty("spring.datasource.tomcat.test-while-idle")));
properties.setTestOnReturn(from(environment.getProperty("spring.datasource.tomcat.test-on-return")));
properties.setTimeBetweenEvictionRunsMillis(environment.getProperty("spring.datasource.tomcat.time-between-eviction-runs-millis", Integer.class));
properties.setMinEvictableIdleTimeMillis(environment.getProperty("spring.datasource.tomcat.min-evictable-idle-time-millis", Integer.class));
properties.setRemoveAbandoned(from(environment.getProperty("spring.datasource.tomcat.remove-abandoned")));
properties.setRemoveAbandonedTimeout(environment.getProperty("spring.datasource.tomcat.remove-abandoned-timeout", Integer.class));
properties.setLogAbandoned(from(environment.getProperty("spring.datasource.tomcat.log-abandoned")));
properties.setLogValidationErrors(from(environment.getProperty("spring.datasource.tomcat.log-validation-errors")));
properties.setJdbcInterceptors(environment.getProperty("spring.datasource.tomcat.jdbc-interceptors"));
return new org.apache.tomcat.jdbc.pool.DataSource(properties);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…