我在项目中配置了spring.datasource.max-wait = 3000,并且当spring.datasource.url错误时,我认为它将在3秒后引发Exception。但这并没有生效。它仍然花费超过3s(约5m)的时间来抛出Exception。为什么?
springboot的版本是v1.5.8.RELEASE
这样的配置和代码
spring:
datasource:
master:
url: jdbc:mysql://172.16.11.229:3306/tc_ums?zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=utf-8
username: root
password: 1234
driver-class-name: com.mysql.jdbc.Driver
maxActive: 10
maxIdle: 5
minIdle: 5
initialSize: 5
minEvictableIdleTimeMillis: 3600000
timeBetweenEvictionRunsMillis: 1200000
test-while-idle: true
validation-query: SELECT 1
max-wait: 3000
slave00:
url: jdbc:mysql://172.16.11.229:3306/tc_ums?zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=utf-8
username: root
password: 1234
driver-class-name: com.mysql.jdbc.Driver
maxActive: 10
maxIdle: 5
minIdle: 5
initialSize: 5
minEvictableIdleTimeMillis: 1800000
timeBetweenEvictionRunsMillis: 300000
test-while-idle: true
validation-query: SELECT 1
max-wait: 3000
@Bean
@Primary
@ConfigurationProperties(prefix="spring.datasource.master")
public DataSource MasterDataSource() {
return new DataSource();
}
@Bean
@ConfigurationProperties(prefix="spring.datasource.slave00")
public DataSource SlaveDataSource00() {
return new DataSource();
}
@Bean
public DynamicDataSource dataSource(@Qualifier("MasterDataSource") DataSource masterDataSource,
@Qualifier("SlaveDataSource00") DataSource slaveDataSource00) {
Map<Object, Object> targetDataSources = new HashMap<Object, Object>();
targetDataSources.put(DatabaseType.master, masterDataSource);
targetDataSources.put(DatabaseType.slave00, slaveDataSource00);
DynamicDataSource dataSource = new DynamicDataSource();
dataSource.setTargetDataSources(targetDataSources);
dataSource.setDefaultTargetDataSource(masterDataSource);
return dataSource;
}