|
@@ -33,14 +33,26 @@ public class DataSourceConfig {
|
|
|
public DataSource masterDataSource() {
|
|
public DataSource masterDataSource() {
|
|
|
return new DruidDataSource();
|
|
return new DruidDataSource();
|
|
|
}
|
|
}
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ @ConfigurationProperties(prefix = "spring.datasource.sop.druid.read")
|
|
|
|
|
+ public DataSource sopReadDataSource() {
|
|
|
|
|
+ return new DruidDataSource();
|
|
|
|
|
+ }
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ @ConfigurationProperties(prefix = "spring.datasource.mysql.druid.slave")
|
|
|
|
|
+ public DataSource readDataSource() {
|
|
|
|
|
+ return new DruidDataSource();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
|
@Primary
|
|
@Primary
|
|
|
- public DynamicDataSource dataSource(@Qualifier("masterDataSource") DataSource masterDataSource, @Qualifier("sopDataSource") DataSource sopDataSource) {
|
|
|
|
|
|
|
+ public DynamicDataSource dataSource(@Qualifier("masterDataSource") DataSource masterDataSource, @Qualifier("sopDataSource") DataSource sopDataSource, @Qualifier("sopReadDataSource") DataSource sopReadDataSource, @Qualifier("readDataSource") DataSource readDataSource) {
|
|
|
Map<Object, Object> targetDataSources = new HashMap<>();
|
|
Map<Object, Object> targetDataSources = new HashMap<>();
|
|
|
targetDataSources.put(DataSourceType.SOP.name(), sopDataSource);
|
|
targetDataSources.put(DataSourceType.SOP.name(), sopDataSource);
|
|
|
|
|
+ targetDataSources.put(DataSourceType.SLAVE.name(), readDataSource);
|
|
|
|
|
+ targetDataSources.put(DataSourceType.SopREAD, sopReadDataSource);
|
|
|
return new DynamicDataSource(masterDataSource, targetDataSources);
|
|
return new DynamicDataSource(masterDataSource, targetDataSources);
|
|
|
}
|
|
}
|
|
|
|
|
|