|
|
@@ -32,51 +32,51 @@ import com.huimv.framework.datasource.DynamicDataSource;
|
|
|
@Configuration
|
|
|
public class DruidConfig
|
|
|
{
|
|
|
- @Bean
|
|
|
- @ConfigurationProperties("spring.datasource.druid.master")
|
|
|
- public DataSource masterDataSource(DruidProperties druidProperties)
|
|
|
- {
|
|
|
- DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
|
|
- return druidProperties.dataSource(dataSource);
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- @ConfigurationProperties("spring.datasource.druid.slave")
|
|
|
- @ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true")
|
|
|
- public DataSource slaveDataSource(DruidProperties druidProperties)
|
|
|
- {
|
|
|
- DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
|
|
- return druidProperties.dataSource(dataSource);
|
|
|
- }
|
|
|
-
|
|
|
- @Bean(name = "dynamicDataSource")
|
|
|
- @Primary
|
|
|
- public DynamicDataSource dataSource(DataSource masterDataSource)
|
|
|
- {
|
|
|
- Map<Object, Object> targetDataSources = new HashMap<>();
|
|
|
- targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource);
|
|
|
- setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource");
|
|
|
- return new DynamicDataSource(masterDataSource, targetDataSources);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置数据源
|
|
|
- *
|
|
|
- * @param targetDataSources 备选数据源集合
|
|
|
- * @param sourceName 数据源名称
|
|
|
- * @param beanName bean名称
|
|
|
- */
|
|
|
- public void setDataSource(Map<Object, Object> targetDataSources, String sourceName, String beanName)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- DataSource dataSource = SpringUtils.getBean(beanName);
|
|
|
- targetDataSources.put(sourceName, dataSource);
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- }
|
|
|
- }
|
|
|
+// @Bean
|
|
|
+// @ConfigurationProperties("spring.datasource.druid.master")
|
|
|
+// public DataSource masterDataSource(DruidProperties druidProperties)
|
|
|
+// {
|
|
|
+// DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
|
|
+// return druidProperties.dataSource(dataSource);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Bean
|
|
|
+// @ConfigurationProperties("spring.datasource.druid.slave")
|
|
|
+// @ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true")
|
|
|
+// public DataSource slaveDataSource(DruidProperties druidProperties)
|
|
|
+// {
|
|
|
+// DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
|
|
+// return druidProperties.dataSource(dataSource);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Bean(name = "dynamicDataSource")
|
|
|
+// @Primary
|
|
|
+// public DynamicDataSource dataSource(DataSource masterDataSource)
|
|
|
+// {
|
|
|
+// Map<Object, Object> targetDataSources = new HashMap<>();
|
|
|
+// targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource);
|
|
|
+// setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource");
|
|
|
+// return new DynamicDataSource(masterDataSource, targetDataSources);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 设置数据源
|
|
|
+// *
|
|
|
+// * @param targetDataSources 备选数据源集合
|
|
|
+// * @param sourceName 数据源名称
|
|
|
+// * @param beanName bean名称
|
|
|
+// */
|
|
|
+// public void setDataSource(Map<Object, Object> targetDataSources, String sourceName, String beanName)
|
|
|
+// {
|
|
|
+// try
|
|
|
+// {
|
|
|
+// DataSource dataSource = SpringUtils.getBean(beanName);
|
|
|
+// targetDataSources.put(sourceName, dataSource);
|
|
|
+// }
|
|
|
+// catch (Exception e)
|
|
|
+// {
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 去除监控页面底部的广告
|