SpringBoot项目去除druid监控的底部广告

文章目录

  • 一、阿里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的请求,重新处理后用正则替换相关的广告代码片段.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/523320.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

精简linux操作系统,Tiny Core Linux—仅10多MB的精简Linux 操作系统发行版

Tiny Core Linux是一款很简约的桌面Linux&#xff0c;体积小且可高度可扩展&#xff0c;基于Linux 3.x内核、Busybox、Tiny X、FLTK图形用户界面、JWM窗口管理器。像其他操作系统最少也要几百MB了&#xff0c;Tiny Core Linux不仅体积小&#xff0c;对硬件配置要求也很高&#…

面试官问你MyBatis中有哪些设计模式,把这篇文章发给他

戳蓝字“CSDN云计算”关注我们哦&#xff01;作者 | 疯狂的蚂蚁来源 | https://dwz.cn/KFgol1De之前总结过一篇Spring中用到了哪些设计模式&#xff1a;《面试官:“谈谈Spring中都用到了那些设计模式?”》&#xff0c;昨晚看到了一篇很不错的一篇介绍MyBatis中都用到了那些设计…

Linux 启动mysql提示表不存在

编辑my.cnf 设置大小写敏感配置在 vim /etc/my.cnf #添加lower_case_table_names1,忽略大小写 #重启MYSQL服务 service mysql restart&#xff0c;

linux 定时器 代码,linux C++ 定时器代码

linux C 定时器代码&#xff1a;#include #include #include using namespace std;/*union sigval{int sival_int; //integer valuevoid *sival_ptr; //pointer value};struct sigevent{int sigev_notify; //notification typeint sigev_signo; //signal numberunion sigval …

MySQL启动出现The server quit without updating PID file错误解决办法

解决办法其实很简单&#xff1a; 将 /etc/mysql 下的 my.cnf 文件删除&#xff0c;再次启动MySQL服务 删除前注意备份

腾讯云首次公开边缘计算网络开源平台,拥抱5G与万物互联

6月25日&#xff0c;由Cloud Native Computing Foundation (CNCF) 主办的云原生技术大会在上海举办&#xff0c;腾讯云对外展示自身在边缘计算领域的最新进展&#xff0c;首次公开腾讯智能边缘计算网络平台TSEC&#xff08;Tencent Smart Edge Connector&#xff09;&#xff0…

linux输入qsub显示错误,linux – 使用qsub运行shellscript的’意外的文件结束’和’错误导入功能定义’错误...

我有以下shellscript&#xff1a;#!/bin/shcd /sw/local/bin/export LD_LIBRARY_PATH/sw/local/lib:/usr/local/Trolltech/Qt-4.7.2/lib:$LD_LIBRARY_PATH./FeatureFinderRaw -in /homes/JG-C1-18.mzML -out /homes/test_remove_after_use.featureXML -threads 20当我从自己的命…

解决SecureCRT与SecureFX中文乱码问题

文章目录一、SecureCRT中文乱码问题解决方法&#xff1a;二、SecureFX中文乱码问题解决方法&#xff1a;2.1. 找到SecureFX配置文件夹2.2. 在配置文件夹下的Sessions子目录中&#xff0c;找到SecureCRT连接对应的Session文件&#xff08;.ini扩展名&#xff09;&#xff0c;双击…

OpenStack精华问答 | OpenStack服务介绍

关于OpenStack的争议,从未停止&#xff0c;每每关于它的消息&#xff0c;都会一石激起千层浪。今天就让我们看看关于OpenStack的问答吧。1Q : OpenStack服务介绍A : MySQL为各个服务器提供数据存储RabbitMq:为各个服务之间提供通信认证和服务注册Keystone&#xff1a;为各个服务…

实战04_redis-cluster集群搭建

接上一篇:实战_03_Redis基础命令https://blog.csdn.net/weixin_40816738/article/details/99213524 #安装gcc yum install gcc-c #使用yum命令安装 ruby &#xff08;我们需要使用ruby脚本来实现集群搭建&#xff09; yum install ruby yum install rubygems #将redis源码包上…

linux网站渗透工具包,ubuntu下安装 kali linux 渗透工具包

相信用过linux系统的盆友都听说过kali linux 它是一个非常好的用于渗透测试的Linux发行版。但是如何在ubuntu下使用kali linux 的渗透工具嘞&#xff01;LionSec开发出了一个python工具&#xff0c;叫做Katoolin&#xff0c;它可以让你在其他Linux发行版上使用Kali的全部工具。…

OCP China Day“登陆”,最新技术、方案吸睛!

戳蓝字“CSDN云计算”关注我们哦&#xff01;作者 | 刘晶晶众所周知&#xff0c;OCP在2011年由Facebook发起成立&#xff0c;核心会员超过200家&#xff0c;其中更是包括Google、微软、Intel、IBM等企业&#xff0c;超过7000家企业参与了该社区的活动&#xff1b;2018年OCP非董…

实战_05_SpringBoot整合redis单机版本

接上一篇&#xff1a;实战04_redis-cluster集群搭建https://blog.csdn.net/weixin_40816738/article/details/100635263 下一篇&#xff1a;实战_06_SpringBoot整合edis-cluster集群版本https://blog.csdn.net/weixin_40816738/article/details/100658669

linux下字体怎么安装方法,linux安装字体方法

1.查看系统中文字体#fc-list :langzh2.如果提示commont not fount 说明为安装fontconfig3.安装fontconfig#yum -y install fontconfig4.再次查看系统中文字体#fc-list :langzh5.确认是否存在字体 -->> simhei.ttf6.创建目录&#xff1a;#mkdir -p /usr/share/fonts/my_fo…

实战_06_SpringBoot整合redis-cluster集群版本

接上一篇&#xff1a;实战_05_SpringBoot整合redis单机版本https://blog.csdn.net/weixin_40816738/article/details/100658608

linux中ssh启动报错,Linux(Ubuntu18)中启动ssh时的报错

今天配置了一台新的Ubuntu的机器&#xff0c;在修改完ssh的配置文件并准备开启ssh的时候&#xff0c;无论是启动ssh&#xff1a;/etc/init/d/ssh start还是重启ssh服务&#xff1a;/etc/init/d/ssh restart都显示错误&#xff1a;Starting ssh (via systemctl): ssh.serviceJob…

SpringBoot集成Shiro前后端分离使用redis做缓存

文章目录一 、shiro介绍1、基础介绍2、基本功能点3、基本流程图二、 常用的权限管理表关系2.1. 表组成2.2. 表结构三、实战案例3.1. 案例介绍3.2. 依赖3.3. Shiro全局配置3.4. 自定义ShiroRealm3.5. ShiroUtils3.6. 自定义SessionManager3.7. 登录/出主方法3.8. 测试主方法四、…

边缘计算容器化是否有必要?

戳蓝字“CSDN云计算”关注我们哦&#xff01;作者 | Steve来源 | 边缘计算中文社区简要由于容器有轻量级、安全性、秒级启动等优秀的特性&#xff0c;容器天然的轻量化和可移植性&#xff0c;非常适合边缘计算的场景&#xff0c;这一点边缘计算的厂家和开发者们都心知肚明。而且…

ipcp协议 Linux,Linux命令Man解释:PPPD(8) :点对点daemon协议

名称pppd - 点对点协定隐形程式(Point to Point Protocol daemon)语法pppd [ 选项 ] [ 终端设备名称(tty_name) ] [ 速率 ]描述这个点对点协定 (PPP) 提供一种在点对点串列线路上传输资料流(datagrams) 的方法。PPP 是由三个部份所组成的&#xff1a;一个在串列线路上封装(enca…

linux查看每个文件夹占空间大小

文章目录进入所在目录&#xff0c;执行以下命令&#xff1a;例&#xff1a;查看/app目录下面&#xff0c;每个目录的空间磁盘占比情况cd /app du -sh *