content: package site.alanliang.geekblog.config;
  
  import com.alibaba.druid.support.http.StatViewServlet;
  import com.alibaba.druid.support.http.WebStatFilter;
  import org.springframework.boot.web.servlet.FilterRegistrationBean;
  import org.springframework.boot.web.servlet.ServletRegistrationBean;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  
  /**
   * @Descriptin TODO
   * @Author AlanLiang
   * Date 2020/4/25 20:00
   * Version 1.0
   **/
  @Configuration
  public class DruidConfig {
      /**
       * 主要实现WEB监控的配置处理
       */
      @Bean
      public ServletRegistrationBean<StatViewServlet> druidServlet() {
          // 现在要进行druid监控的配置处理操作
          ServletRegistrationBean<StatViewServlet> servletRegistrationBean = new ServletRegistrationBean<>(
                  new StatViewServlet(), "/druid/*");
          // 控制台管理用户名
          servletRegistrationBean.addInitParameter("loginUsername", "admin");
          // 控制台管理密码
          servletRegistrationBean.addInitParameter("loginPassword", "admin");
          // 是否可以重置数据源，禁用HTML页面上的“Reset All”功能
          servletRegistrationBean.addInitParameter("resetEnable", "false");
          return servletRegistrationBean;
      }
  
      @Bean
      public FilterRegistrationBean<WebStatFilter> filterRegistrationBean() {
          FilterRegistrationBean<WebStatFilter> filterRegistrationBean = new FilterRegistrationBean<>();
          filterRegistrationBean.setFilter(new WebStatFilter());
          //所有请求进行监控处理
          filterRegistrationBean.addUrlPatterns("/*");
          //添加不需要忽略的格式信息
          filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.css,/druid/*,/static/**");
          return filterRegistrationBean;
      }
  }
  