多数据源的配置

@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);
}

}
posted @ 2019-08-08 14:51  烟雨蒙尘  阅读(324)  评论(0编辑  收藏  举报