我们有一个Spring引导应用程序,使用hikariCP作为连接池和多个数据源来处理长作业处理(基本上它使用相同的连接字符串,具有更长的超时和更少的连接数)
自1.5.2.RELEASE升级以来,只有第一个用@Primary注释的数据源才有其内务处理和池线程启动。虽然调试显示正在执行数据源初始化,但是简单地丢弃了第二个。
使用1.5.1.RELEASE这个工作正常,两组线程都会启动。
以下是我们的数据源定义
import java.util.Properties;
import javax.sql.DataSource;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import lombok.AllArgsConstructor;
@Profile("hikari")
@Validated
@AllArgsConstructor(onConstructor = @__(@Autowired))
@Component
class HikariDataSourceConfig
{
private final DataSourceConfig dataSourceConfig;
protected Properties setDataSourceProperties()
{
final Properties dataSourceProperties = new Properties();
dataSourceProperties.put("driverType", "thin");
dataSourceProperties.put("user", this.dataSourceConfig.getUsername());
dataSourceProperties.put("password", this.dataSourceConfig.getPassword());
dataSourceProperties.put("serverName", this.dataSourceConfig.getServer());
dataSourceProperties.put("portNumber", String.valueOf(this.dataSourceConfig.getPort()));
dataSourceProperties.put("databaseName", this.dataSourceConfig.getSid());
return dataSourceProperties;
}
protected HikariDataSource initializeDataSource(final int maximumPoolSize)
{
final HikariDataSource dataSource = new HikariDataSource();
dataSource.setMaximumPoolSize(maximumPoolSize);
dataSource.setValidationTimeout(this.dataSourceConfig.getValidationTimeout() * 1000L);
dataSource.setDataSourceClassName("oracle.jdbc.pool.OracleDataSource");
dataSource.setConnectionTimeout(this.dataSourceConfig.getConnectionTimeout() * 1000L);
dataSource.setMaxLifetime(this.dataSourceConfig.getMaxLifetime() * 1000L);
dataSource.setIdleTimeout(this.dataSourceConfig.getIdleTimeout() * 1000L);
dataSource.setAutoCommit(false);
return dataSource;
}
@Bean(destroyMethod = "close")
@Primary
public DataSource dataSource()
{
final HikariDataSource dataSource = initializeDataSource(this.dataSourceConfig.getMaximumPoolSize());
dataSource.setPoolName(DataSourceConfig.CONNECTION_POOL_DEFAULT_NAME);
dataSource.setLeakDetectionThreshold(this.dataSourceConfig.getLeakDetectionThreshold() * 1000L);
dataSource.setDataSourceProperties(setDataSourceProperties());
return dataSource;
}
@Bean(name = DataSourceConfig.DATASOURCE_ALT_NAME, destroyMethod = "close")
public DataSource slowDataSource()
{
final HikariDataSource dataSource = initializeDataSource(this.dataSourceConfig.getWorkingQueueSize());
dataSource.setMinimumIdle(1);
dataSource.setPoolName(DataSourceConfig.CONNECTION_POOL_ALT_NAME);
dataSource.setLeakDetectionThreshold(this.dataSourceConfig.getSlowJobLeakDetectionThreshold() * 1000L);
dataSource.setDataSourceProperties(setDataSourceProperties());
return dataSource;
}
}
有没有办法配置spring以再次允许克隆的数据源?
使用的版本:
- 修改
1.5.2.RELEASE和1.5.3.RELEASE
都失败了- 修改2
我尝试将第二个数据源绑定到不同的数据库,但是出现同样的问题,辅助数据源池无法启动。