我正在尝试使数据源url在外部可配置(从Restful服务响应中获取),但是我需要知道其他数据源属性是否仍然保持不变并应用于数据源Bean
import javax.sql.DataSource;
.
.
@Configuration
public class DataSourceConfig(){
@Bean
public DataSource dataSource() {
String userName = env.getRequiredProperty("spring.datasource.username");
String password = env.getRequiredProperty("spring.datasource.password");
String url = getTheJdbcUrlFromExternalServiceProvider();
return DataSourceBuilder.create().url(url).username(userName).password(password).build();
}
}
和其余数据源属性在application.properties文件中配置
spring.datasource.tomcat.max-active=100
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.min-idle=2
spring.datasource.tomcat.test-while-idle=true
spring.datasource.tomcat.time-between-eviction-runs-millis=600000
spring.datasource.tomcat.min-evictable-idle-time-millis=60000
spring.datasource.tomcat.validation-query=select 1 from dual
spring数据源配置属性是否应用于创建的数据源bean,以及如何验证相同属性?如果没有,如何从外部配置数据库URL?