jdk1.7, springboot1.5.8.RELEASE, druid1.1.5,nutz1.r.66git
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; }
@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); }
@Autowired NutDao dao; @Autowired @Qualifier("sdao") NutDao sdao;
當存在多個數據源時,最好加上@Primary註解,這樣默認使用這個鏈接,不須要使用Qualifier註解說明使用某個鏈接。spring
https://gitee.com/strictnerd/rdb-esspringboot