环境说明
配置步骤
- 配置文件(application.properties)
t1.data1.driver-class-name=oracle.jdbc.driver.OracleDriver
t1.data1.url=jdbc:oracle:thin:@171.12.84.126:1521:ora11g
t1.data1.username=oracle_78
t1.data1.password=oracle_78
t1.data1.initialSize=5
t1.data1.minIdle=5
t1.data1.maxActive=100
t1.data1.maxWait=60000
t1.data1.timeBetweenEvictionRunsMillis=60000
t1.data1.minEvictableIdleTimeMillis=300000
t1.data1.validationQuery=SELECT 1 FROM DUAL
t1.data1.testWhileIdle=true
t1.data1.testOnBorrow=false
t1.data1.testOnReturn=false
t1.data1.filters=stat,wall,log4j
t1.data1.poolPreparedStatements = true
t1.data1.maxOpenPreparedStatements = 20
t1.data1.logSlowSql=true
t.data.driver-class-name=oracle.jdbc.driver.OracleDriver
t.data.url=jdbc:oracle:thin:@171.12.84.126:1521:ora11g
t.data.username=oracle_102
t.data.password=oracle_102
t.data.initialSize=5
t.data.minIdle=5
t.data.maxActive=100
t.data.maxWait=60000
t.data.timeBetweenEvictionRunsMillis=60000
t.data.minEvictableIdleTimeMillis=300000
t.data.validationQuery=SELECT 1 FROM DUAL
t.data.testWhileIdle=true
t.data.testOnBorrow=false
t.data.testOnReturn=false
t.data.filters=stat,wall,log4j
t.data.poolPreparedStatements = true
t.data.maxOpenPreparedStatements = 20
t.data.logSlowSql=true
- 配置多数据源
@Bean(name = "ds")
@ConfigurationProperties(prefix = "t.data")
public DataSource dataSource() throws SQLException {
DataSource build = DataSourceBuilder.create().type(DruidDataSource.class).build();
return build;
}
@Primary
@Bean
@ConfigurationProperties(prefix = "t1.data1")
public DataSource dataSource1() throws SQLException {
DataSource build = DataSourceBuilder.create().type(DruidDataSource.class).build();
return build;
}
- 集成druid
@Primary
@Primary
@Bean
public NutDao dao(DataSource dataSource) {
return new NutDao(dataSource);
}
@Bean(name = "sdao")
public NutDao sdao(@Qualifier("ds") DataSource dataSource) {
return new NutDao(dataSource);
}
- crud操作
@Autowired
NutDao dao;
@Autowired
@Qualifier("sdao")
NutDao sdao;
说明
源码参考
https://gitee.com/strictnerd/rdb-es