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


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

    有两种方案

    1. 编写配置类,进行广告的去除
      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;
      
      /**
       * Druid 底部广告去除
       */
      @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
           */
          @Bean
          public 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() {
                  @Override
                  public void init(FilterConfig filterConfig) throws ServletException {
                  }
      
                  @Override
                  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
                      chain.doFilter(request, response);
                      // 重置缓冲区,响应头不会被重置
                      response.resetBuffer();
                      // 获取common.js
                      String text = Utils.readFromResource(filePath);
                      // 正则替换banner, 除去底部的广告信息
                      text = text.replaceAll("
      "
      , ""); text = text.replaceAll("powered.*?shrek.wang", ""); response.getWriter().write(text); } @Override public void destroy() { } }; FilterRegistrationBean registrationBean = new FilterRegistrationBean(); registrationBean.setFilter(filter); registrationBean.addUrlPatterns(commonJsPattern); return registrationBean; } }
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
      • 25
      • 26
      • 27
      • 28
      • 29
      • 30
      • 31
      • 32
      • 33
      • 34
      • 35
      • 36
      • 37
      • 38
      • 39
      • 40
      • 41
      • 42
      • 43
      • 44
      • 45
      • 46
      • 47
      • 48
      • 49
      • 50
      • 51
      • 52
      • 53
      • 54
      • 55
      • 56
      • 57
      • 58
      • 59
      • 60
      • 61
      • 62
      • 63
      • 64
      • 65
      • 66
      • 67
      • 68
      • 69
      • 70
      • 71
    2. 第二种方案
      直接修改druid.jar包里面的内容
      修改common.js文件
      在这里插入图片描述
      里面的footer中的内容对应的就是广告,注释掉即可
    var html ='';
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 相关阅读:
    Redis
    Nginx网站服务
    NumPy 数组创建方法与索引访问详解
    【Python编程练习】字符串操作
    Spring cloud Sentinel介绍和安装
    python实现模拟器的重启
    基于Java的交通事故档案管理系统设计与实现(源码+lw+部署文档+讲解等)
    云原生Kubernetes:二进制部署K8S多Master架构(三)
    算法进阶指南图论 道路与航线
    Unity的IPreprocessBuildWithReport:深入解析与实用案例
  • 原文地址:https://blog.csdn.net/weixin_44021888/article/details/126060688