正在显示
1 个修改的文件
包含
22 行增加
和
2 行删除
| @@ -19,6 +19,7 @@ import com.alibaba.druid.pool.DruidDataSource; | @@ -19,6 +19,7 @@ import com.alibaba.druid.pool.DruidDataSource; | ||
| 19 | import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; | 19 | import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; |
| 20 | import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties; | 20 | import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties; |
| 21 | import com.alibaba.druid.util.Utils; | 21 | import com.alibaba.druid.util.Utils; |
| 22 | +import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 22 | import com.ruoyi.framework.aspectj.lang.enums.DataSourceType; | 23 | import com.ruoyi.framework.aspectj.lang.enums.DataSourceType; |
| 23 | import com.ruoyi.framework.config.properties.DruidProperties; | 24 | import com.ruoyi.framework.config.properties.DruidProperties; |
| 24 | import com.ruoyi.framework.datasource.DynamicDataSource; | 25 | import com.ruoyi.framework.datasource.DynamicDataSource; |
| @@ -50,15 +51,34 @@ public class DruidConfig | @@ -50,15 +51,34 @@ public class DruidConfig | ||
| 50 | 51 | ||
| 51 | @Bean(name = "dynamicDataSource") | 52 | @Bean(name = "dynamicDataSource") |
| 52 | @Primary | 53 | @Primary |
| 53 | - public DynamicDataSource dataSource(DataSource masterDataSource, DataSource slaveDataSource) | 54 | + public DynamicDataSource dataSource(DataSource masterDataSource) |
| 54 | { | 55 | { |
| 55 | Map<Object, Object> targetDataSources = new HashMap<>(); | 56 | Map<Object, Object> targetDataSources = new HashMap<>(); |
| 56 | targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource); | 57 | targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource); |
| 57 | - targetDataSources.put(DataSourceType.SLAVE.name(), slaveDataSource); | 58 | + setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource"); |
| 58 | return new DynamicDataSource(masterDataSource, targetDataSources); | 59 | return new DynamicDataSource(masterDataSource, targetDataSources); |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 61 | /** | 62 | /** |
| 63 | + * 设置数据源 | ||
| 64 | + * | ||
| 65 | + * @param targetDataSources 备选数据源集合 | ||
| 66 | + * @param sourceName 数据源名称 | ||
| 67 | + * @param beanName bean名称 | ||
| 68 | + */ | ||
| 69 | + public void setDataSource(Map<Object, Object> targetDataSources, String sourceName, String beanName) | ||
| 70 | + { | ||
| 71 | + try | ||
| 72 | + { | ||
| 73 | + DataSource dataSource = SpringUtils.getBean(beanName); | ||
| 74 | + targetDataSources.put(sourceName, dataSource); | ||
| 75 | + } | ||
| 76 | + catch (Exception e) | ||
| 77 | + { | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + /** | ||
| 62 | * 去除监控页面底部的广告 | 82 | * 去除监控页面底部的广告 |
| 63 | */ | 83 | */ |
| 64 | @SuppressWarnings({ "rawtypes", "unchecked" }) | 84 | @SuppressWarnings({ "rawtypes", "unchecked" }) |
-
请 注册 或 登录 后发表评论