多数据源的配置

@Configuration
@PropertySource(value = {
"classpath:db.properties"
})
public class DBConfig {
@Bean(name = "writeDataSource")
@ConfigurationProperties(prefix = "spring.datasource.data")
public DataSource writeDataSource() {
DruidDataSource druidDataSource = new DruidDataSource();
return druidDataSource;
}

@Bean(name = "writeJdbcTemplate")
public JdbcTemplate writeJdbcTemplate(@Qualifier("writeDataSource") DataSource writeDataSource) {

return new JdbcTemplate(writeDataSource);
}


@Bean(name = "readDataSource")
@ConfigurationProperties(prefix = "spring.datasource.conf")
public DataSource readDataSource() {
DruidDataSource druidDataSource = new DruidDataSource();
return druidDataSource;
}

@Bean(name = "readJdbcTemplate")
public JdbcTemplate readJdbcTemplate(@Qualifier("readDataSource") DataSource readDataSource) {

return new JdbcTemplate(readDataSource);
}

}
原文地址:https://www.cnblogs.com/zhuguangzhe/p/11321113.html