文章目录

  • 一、阿里Druid广告的介绍
  • 二、引入Druid的Starter依赖
  • 三、编写配置类,进行广告的去除
  • 四 、启动项目进行测试
  • 五、原理说明

一、阿里Druid广告的介绍

如果使用的是阿里Druid的数据库连接池,那么会自带一个数据库的监控页面. 但是其页面底部会有阿里的广告,如下图所示,并且在其最下方的作者申明中, 有一个作者的链接,会直接到澳门赌场的页面,这是极其不友好的.因此需要进行去除

二、引入Druid的Starter依赖

对于SpringBoot项目.阿里druid有其专门的druid-spring-boot-starter版本, 我使用的是1.1.13版本

<dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.1.13</version></dependency>

三、编写配置类,进行广告的去除

在SpringBoot项目中编写一个RemoveDruidAdConfig配置类,进行监控页面广告的去除

package com.gblfy.web.core.config;import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
import com.alibaba.druid.util.Utils;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import javax.servlet.*;
import java.io.IOException;/*** @author gblfy* @ClassNme RemoveDruidAdConfig* @Description Druid 底部广告去除* @Date 2019/9/8 8:38* @version1.0*/
@Configuration
@ConditionalOnWebApplication
@AutoConfigureAfter(DruidDataSourceAutoConfigure.class)
@ConditionalOnProperty(name = "spring.datasource.druid.stat-view-servlet.enabled", havingValue = "true", matchIfMissing = true)
public class RemoveDruidAdConfig {/*** 方法名: removeDruidAdFilterRegistrationBean* 方法描述:  除去页面底部的广告** @param properties* @return org.springframework.boot.web.servlet.FilterRegistrationBean* @throws*/@Beanpublic FilterRegistrationBean removeDruidAdFilterRegistrationBean(DruidStatProperties properties) {// 获取web监控页面的参数DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();// 提取common.js的配置路径String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*";String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");final String filePath = "support/http/resources/js/common.js";//创建filter进行过滤Filter filter = new Filter() {@Overridepublic void init(FilterConfig filterConfig) throws ServletException {}@Overridepublic void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {chain.doFilter(request, response);// 重置缓冲区,响应头不会被重置response.resetBuffer();// 获取common.jsString text = Utils.readFromResource(filePath);// 正则替换banner, 除去底部的广告信息text = text.replaceAll("<a.*?banner\"></a><br/>", "");text = text.replaceAll("powered.*?shrek.wang</a>", "");response.getWriter().write(text);}@Overridepublic void destroy() {}};FilterRegistrationBean registrationBean = new FilterRegistrationBean();registrationBean.setFilter(filter);registrationBean.addUrlPatterns(commonJsPattern);return registrationBean;}
}

四 、启动项目进行测试

再次启动项目,可以看到其底部的广告信息已经没有了.

五、原理说明

之所以底部有广告,是因为其引入的druid jar包的common.js中的内容

面的这段footer的内容, 就是广告的来源.

var html ='<footer class="footer">'+'          <div class="container">'+'<a href="https://render.alipay.com/p/s/taobaonpm_click/druid_banner_click" target="new"><img src="https://render.alipay.com/p/s/taobaonpm_click/druid_banner"></a><br/>' +'   powered by <a href="https://github.com/alibaba/" target="_blank">Alibaba</a> & sandzhang & <a href="http://melin.iteye.com/" target="_blank">melin</a> & <a href="https://github.com/shrekwang" target="_blank">shrek.wang</a>'+'          </div>'+' </footer>';

在RemoveDruidAdConfig 配置类中就是使用过滤器过滤common.js的请求,重新处理后用正则替换相关的广告代码片段.

SpringBoot项目去除druid监控的底部广告相关推荐

  1. SpringBoot项目去除druid监控的阿里广告

    一. 阿里Druid广告的介绍 如果使用的是阿里Druid的数据库连接池,那么会自带一个数据库的监控页面. 但是其页面底部会有阿里的广告,如下图所示,并且在其最下方的作者申明中, 有一个作者的链接,会 ...

  2. springboot下配置druid监控

    springboot下配置druid监控 在springboot中引用的包 相关配置 页面访问 获取druid监控数据 官方介绍如下:Druid是Java语言中最好的数据库连接池.Druid能够提供强 ...

  3. 去除druid监控页面中的广告

    druid监控广告去除 @Bean@ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled ...

  4. springboot系列学习(十九):springboot项目整合Druid,Druid到底是什么,他是在项目中如何使用的

    目录 Druid是什么 先看一下之前的整合的jdbc使用的数据源是什么 创建一个springboot项目,导入Druid依赖 写一个Druid的配置类 yml文件和配置类绑定,这个之前就写过 解释以上 ...

  5. 为springboot项目添加springboot-admin监控

    我们知道spring-boot-actuator暴露了大量统计和监控信息的端点,spring-boot-admin 就是为此提供的监控项目. 先来看看大概会提供什么样的功能 从图中可以看出,主要内容都 ...

  6. SpringBoot项目的Druid监控配置

    1. 引入druid的Maven依赖 <dependency><groupId>com.alibaba</groupId><artifactId>dru ...

  7. SpringBoot项目中Druid自动登录

    Druid是什么 2019最受欢迎中国开源软件评选投票https://www.oschina.net/project/top_cn_2019 请参与投票. Druid是Java语言中最好的数据库连接池 ...

  8. Springboot 中配置 druid 监控

    一.druid 的 maven 依赖 <!-- druid依赖 --> <dependency><groupId>com.alibaba</groupId&g ...

  9. Druid监控页面配置用户密码、去除Ad

    1.druid依赖 <!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter --> &l ...

最新文章

  1. SpringBoot 连接mysql踩到的坑
  2. php.ini 中文版第二部分(关于这个配制文件)
  3. java基础---二维数组方面的一些小编程
  4. android browser 书签 路径,Android Browser学习七 书签历史模块: 书签UI的实现(2)
  5. android学习笔记48——SQLite
  6. 视频抽帧并存图 python_使用Python实现跳帧截取视频帧
  7. 走进JavaScript
  8. 如何在命令行更改IP地址
  9. Python数据分析学习系列 十四 数据分析案例
  10. AEC 声学回声消除
  11. ubuntu 16.04 桌面版 双击自动删除文字 解决方案
  12. shell 补齐路径_Linux中10个有用的命令行补全例子
  13. AWS DynamoDB 常用操作
  14. 攻防世界-MISC-Time_losing
  15. ssm+java计算机毕业设计大学生就业管理系统26cjn(程序+lw+源码+远程部署)
  16. 计算机网络基础——应用层
  17. 详解java集合框架
  18. Java基础算法题(02):古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
  19. java 程序员英语自我介绍_程序员英语面试自我介绍范文
  20. SSCOM3.2无法保存窗口的问题的解决

热门文章

  1. 不会演讲的你,一开口就输了!
  2. keepalived的安装与添加服务
  3. zookeeper结构和命令详解
  4. MaxCompute 挑战使用SQL进行序列数据处理
  5. Java编程技巧之样板代码
  6. 聚焦2020云栖大会 边缘计算专场畅谈技术应用创新
  7. 阿里云应用高可用 AHAS 正式商用,可一键提升云上应用可用性
  8. 一枚戒指,一场仪式,这件事阿里巴巴坚持了15年
  9. TableStore实战:DLA+SQL实时分析TableStore
  10. I+关系网络分析发布,提供完整的可视化分析和关系引擎功能