Druid监控页面配置用户密码、去除Ad
短信预约 -IT技能 免费直播动态提醒
1.druid依赖
com.alibaba druid-spring-boot-starter 1.2.16
监控页面访问路径:http://localhost:21018/context-path/druid/index.html
2.Druid监控页面设置用户密码
@Beanpublic ServletRegistrationBean statViewServlet() {final ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid@Configurationpublic class DruidConfig {@Beanpublic ServletRegistrationBean statViewServlet() {final ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid@Beanpublic FilterRegistrationBean webStatFilter() {FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();filterRegistrationBean.setFilter(new WebStatFilter());Map initParams = new HashMap<>(16);initParams.put("exclusions", "/static@Beanpublic StatFilter statFilter() {StatFilter statFilter = new StatFilter();// 慢sql时间设置,即执行时间大于2000毫秒都是慢sqlstatFilter.setSlowSqlMillis(2000L);statFilter.setLogSlowSql(true);statFilter.setMergeSql(true);return statFilter;}@Beanpublic Slf4jLogFilter logFilter() {Slf4jLogFilter slf4jLogFilter = new Slf4jLogFilter();slf4jLogFilter.setDataSourceLogEnabled(true);slf4jLogFilter.setStatementExecutableSqlLogEnable(true);return slf4jLogFilter;}@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 doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {filterChain.doFilter(servletRequest, servletResponse);// 重置缓冲区,响应头不会被重置servletResponse.resetBuffer();// 获取common.jsString text = Utils.readFromResource(filePath);// 正则替换banner, 除去底部的广告信息text = text.replaceAll("
", "");text = text.replaceAll("powered.*?shrek.wang", "");servletResponse.getWriter().write(text);}};FilterRegistrationBean registrationBean = new FilterRegistrationBean();registrationBean.setFilter(filter);registrationBean.addUrlPatterns(commonJsPattern);return registrationBean;}}
来源地址:https://blog.csdn.net/m0_48983233/article/details/129402203
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341