From 2d992db62afdc059989343700cbe2fe40028a768 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 19 Dec 2019 16:21:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=BA=90=E4=B8=8Benabled=3Dfalse=E5=AF=BC=E8=87=B4=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E4=B8=8D=E5=88=B0bean=E5=AF=BC=E8=87=B4=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/framework/config/DruidConfig.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/ruoyi/src/main/java/com/ruoyi/framework/config/DruidConfig.java b/ruoyi/src/main/java/com/ruoyi/framework/config/DruidConfig.java index 26135c88..f0519d5a 100644 --- a/ruoyi/src/main/java/com/ruoyi/framework/config/DruidConfig.java +++ b/ruoyi/src/main/java/com/ruoyi/framework/config/DruidConfig.java @@ -19,6 +19,7 @@ import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties; import com.alibaba.druid.util.Utils; +import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.framework.aspectj.lang.enums.DataSourceType; import com.ruoyi.framework.config.properties.DruidProperties; import com.ruoyi.framework.datasource.DynamicDataSource; @@ -50,13 +51,32 @@ public class DruidConfig @Bean(name = "dynamicDataSource") @Primary - public DynamicDataSource dataSource(DataSource masterDataSource, DataSource slaveDataSource) + public DynamicDataSource dataSource(DataSource masterDataSource) { Map targetDataSources = new HashMap<>(); targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource); - targetDataSources.put(DataSourceType.SLAVE.name(), slaveDataSource); + setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource"); return new DynamicDataSource(masterDataSource, targetDataSources); } + + /** + * 设置数据源 + * + * @param targetDataSources 备选数据源集合 + * @param sourceName 数据源名称 + * @param beanName bean名称 + */ + public void setDataSource(Map targetDataSources, String sourceName, String beanName) + { + try + { + DataSource dataSource = SpringUtils.getBean(beanName); + targetDataSources.put(sourceName, dataSource); + } + catch (Exception e) + { + } + } /** * 去除监控页面底部的广告