|
|
@ -20,6 +20,7 @@ import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
|
|
|
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
|
|
|
|
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
|
|
|
|
import com.alibaba.druid.util.Utils;
|
|
|
|
import com.alibaba.druid.util.Utils;
|
|
|
|
import com.ruoyi.common.enums.DataSourceType;
|
|
|
|
import com.ruoyi.common.enums.DataSourceType;
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
|
|
|
import com.ruoyi.framework.config.properties.DruidProperties;
|
|
|
|
import com.ruoyi.framework.config.properties.DruidProperties;
|
|
|
|
import com.ruoyi.framework.datasource.DynamicDataSource;
|
|
|
|
import com.ruoyi.framework.datasource.DynamicDataSource;
|
|
|
|
|
|
|
|
|
|
|
@ -50,14 +51,33 @@ public class DruidConfig
|
|
|
|
|
|
|
|
|
|
|
|
@Bean(name = "dynamicDataSource")
|
|
|
|
@Bean(name = "dynamicDataSource")
|
|
|
|
@Primary
|
|
|
|
@Primary
|
|
|
|
public DynamicDataSource dataSource(DataSource masterDataSource, DataSource slaveDataSource)
|
|
|
|
public DynamicDataSource dataSource(DataSource masterDataSource)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Map<Object, Object> targetDataSources = new HashMap<>();
|
|
|
|
Map<Object, Object> targetDataSources = new HashMap<>();
|
|
|
|
targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource);
|
|
|
|
targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource);
|
|
|
|
targetDataSources.put(DataSourceType.SLAVE.name(), slaveDataSource);
|
|
|
|
setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource");
|
|
|
|
return new DynamicDataSource(masterDataSource, targetDataSources);
|
|
|
|
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)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 去除监控页面底部的广告
|
|
|
|
* 去除监控页面底部的广告
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -79,6 +99,7 @@ public class DruidConfig
|
|
|
|
public void init(javax.servlet.FilterConfig filterConfig) throws ServletException
|
|
|
|
public void init(javax.servlet.FilterConfig filterConfig) throws ServletException
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
|
|
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
|
|
|
throws IOException, ServletException
|
|
|
|
throws IOException, ServletException
|
|
|
@ -93,6 +114,7 @@ public class DruidConfig
|
|
|
|
text = text.replaceAll("powered.*?shrek.wang</a>", "");
|
|
|
|
text = text.replaceAll("powered.*?shrek.wang</a>", "");
|
|
|
|
response.getWriter().write(text);
|
|
|
|
response.getWriter().write(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void destroy()
|
|
|
|
public void destroy()
|
|
|
|
{
|
|
|
|
{
|
|
|
|