页面广告问题

This commit is contained in:
dingzhongyuan 2021-06-21 16:17:42 +08:00
parent 3a217c9ea2
commit e7e91ecd7b
5 changed files with 91 additions and 145 deletions

View File

@ -5,6 +5,15 @@ spring:
datasource: datasource:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver driverClassName: com.mysql.cj.jdbc.Driver
druid:
statViewServlet:
enabled: true
# 设置白名单,不填则允许所有访问
allow:
url-pattern: /druid/*
# 控制台管理用户名和密码
login-username: ruoyi
login-password: 123456
dynamic: dynamic:
druid: druid:
# 初始连接数 # 初始连接数
@ -12,7 +21,7 @@ spring:
# 最小连接池数量 # 最小连接池数量
minIdle: 10 minIdle: 10
# 最大连接池数量 # 最大连接池数量
maxActive: 20 maxActive: 30
# 配置获取连接等待超时的时间 # 配置获取连接等待超时的时间
maxWait: 60000 maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
@ -29,14 +38,6 @@ spring:
filters: stat # 注意这个值和druid原生不一致默认启动了stat filters: stat # 注意这个值和druid原生不一致默认启动了stat
webStatFilter: webStatFilter:
enabled: true enabled: true
statViewServlet:
enabled: true
# 设置白名单,不填则允许所有访问
allow:
url-pattern: /druid/*
# 控制台管理用户名和密码
login-username: ruoyi
login-password: 123456
filter: filter:
stat: stat:
enabled: true enabled: true
@ -54,10 +55,10 @@ spring:
username: root username: root
password: root123456 password: root123456
# 从库数据源 # 从库数据源
slave: # slave:
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true # url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
username: root # username: root
password: root123456 # password: root123456
# redis 配置 # redis 配置
redis: redis:
# 地址 # 地址

View File

@ -1,22 +1,20 @@
# 数据源配置
spring: spring:
autoconfigure:
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
datasource: datasource:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver driverClassName: com.mysql.cj.jdbc.Driver
druid:
statViewServlet:
enabled: true
# 设置白名单,不填则允许所有访问
allow:
url-pattern: /druid/*
# 控制台管理用户名和密码
login-username: ruoyi
login-password: 123456
dynamic: dynamic:
druid: druid:
# 主库数据源
master:
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
username: root
password: root123456
# 从库数据源
slave:
# 从数据源开关/默认关闭
enabled: false
url:
username:
password:
# 初始连接数 # 初始连接数
initialSize: 5 initialSize: 5
# 最小连接池数量 # 最小连接池数量
@ -36,6 +34,7 @@ spring:
testWhileIdle: true testWhileIdle: true
testOnBorrow: false testOnBorrow: false
testOnReturn: false testOnReturn: false
filters: stat # 注意这个值和druid原生不一致默认启动了stat
webStatFilter: webStatFilter:
enabled: true enabled: true
statViewServlet: statViewServlet:
@ -56,6 +55,17 @@ spring:
wall: wall:
config: config:
multi-statement-allow: true multi-statement-allow: true
datasource:
# 主库数据源
master:
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
username: root
password: root123456
# 从库数据源
# slave:
# url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
# username: root
# password: root123456
# redis 配置 # redis 配置
redis: redis:

View File

@ -1,73 +0,0 @@
//package com.ruoyi.framework.aspectj;
//
//import cn.hutool.core.lang.Validator;
//import com.ruoyi.common.annotation.DataSource;
//import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.core.annotation.AnnotationUtils;
//import org.springframework.core.annotation.Order;
//import org.springframework.stereotype.Component;
//
//import java.util.Objects;
//
///**
// * 多数据源处理
// *
// * @author ruoyi
// */
//@Aspect
//@Order(1)
//@Component
//public class DataSourceAspect
//{
// protected Logger logger = LoggerFactory.getLogger(getClass());
//
// @Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)"
// + "|| @within(com.ruoyi.common.annotation.DataSource)")
// public void dsPointCut()
// {
//
// }
//
// @Around("dsPointCut()")
// public Object around(ProceedingJoinPoint point) throws Throwable
// {
// DataSource dataSource = getDataSource(point);
//
// if (Validator.isNotNull(dataSource))
// {
// DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name());
// }
//
// try
// {
// return point.proceed();
// }
// finally
// {
// // 销毁数据源 在执行方法之后
// DynamicDataSourceContextHolder.clearDataSourceType();
// }
// }
//
// /**
// * 获取需要切换的数据源
// */
// public DataSource getDataSource(ProceedingJoinPoint point)
// {
// MethodSignature signature = (MethodSignature) point.getSignature();
// DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class);
// if (Objects.nonNull(dataSource))
// {
// return dataSource;
// }
//
// return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class);
// }
//}

View File

@ -1,11 +1,19 @@
package com.ruoyi.framework.config; package com.ruoyi.framework.config;
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
import com.alibaba.druid.util.Utils;
import com.baomidou.dynamic.datasource.plugin.MasterSlaveAutoRoutingPlugin; import com.baomidou.dynamic.datasource.plugin.MasterSlaveAutoRoutingPlugin;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.servlet.*;
import java.io.IOException;
/** /**
* 在纯的读写分离环境写操作全部是master读操作全部是slave * 在纯的读写分离环境写操作全部是master读操作全部是slave
* @author ding * @author ding
@ -18,50 +26,50 @@ public class DynamicDataSourceConfig {
return new MasterSlaveAutoRoutingPlugin(); return new MasterSlaveAutoRoutingPlugin();
} }
// /** /**
// * 去除监控页面底部的广告 * 去除监控页面底部的广告
// */ */
// @SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
// @Bean @Bean
// @ConditionalOnProperty(name = "spring.datasource.dynamic.druid.statViewServlet.enabled", havingValue = "true") @ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true")
// public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties) public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties)
// { {
// // 获取web监控页面的参数 // 获取web监控页面的参数
// DruidStatProperties.StatViewServlet config = properties.getStatViewServlet(); DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
// // 提取common.js的配置路径 // 提取common.js的配置路径
// String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*"; String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*";
// String commonJsPattern = pattern.replaceAll("\\*", "js/common.js"); String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
// final String filePath = "support/http/resources/js/common.js"; final String filePath = "support/http/resources/js/common.js";
// // 创建filter进行过滤 // 创建filter进行过滤
// Filter filter = new Filter() Filter filter = new Filter()
// { {
// @Override @Override
// 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
// { {
// chain.doFilter(request, response); chain.doFilter(request, response);
// // 重置缓冲区响应头不会被重置 // 重置缓冲区响应头不会被重置
//// response.resetBuffer(); // response.resetBuffer();
// // 获取common.js // 获取common.js
// String text = Utils.readFromResource(filePath); String text = Utils.readFromResource(filePath);
// // 正则替换banner, 除去底部的广告信息 // 正则替换banner, 除去底部的广告信息
// text = text.replaceAll("<a.*?banner\"></a><br/>", ""); text = text.replaceAll("<a.*?banner\"></a><br/>", "");
// 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()
// { {
// } }
// }; };
// FilterRegistrationBean registrationBean = new FilterRegistrationBean(); FilterRegistrationBean registrationBean = new FilterRegistrationBean();
// registrationBean.setFilter(filter); registrationBean.setFilter(filter);
// registrationBean.addUrlPatterns(commonJsPattern); registrationBean.addUrlPatterns(commonJsPattern);
// return registrationBean; return registrationBean;
// } }
} }

View File

@ -56,7 +56,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override @Override
@DataScope(deptAlias = "d", userAlias = "u", isUser = true) @DataScope(deptAlias = "d", userAlias = "u", isUser = true)
@DS("master") @DS("slave")
public TableDataInfo<SysUser> selectPageUserList(SysUser user) { public TableDataInfo<SysUser> selectPageUserList(SysUser user) {
String dataName = DynamicDataSourceContextHolder.peek(); String dataName = DynamicDataSourceContextHolder.peek();
log.info("自定义方法--获取用户列表---当前数据源名称:"+dataName); log.info("自定义方法--获取用户列表---当前数据源名称:"+dataName);