Spring Boot 中 Druid 的监控页面配置

Druid的性能相比HikariCp等其他数据库连接池有一定的差距,但是数据库的相关属性的监控,别的连接池可能还追不上,如图:

Spring Boot 中 Druid 的监控页面配置

今天写一下 Spring Boot 中监控页面的配置,我是直接将seata中的相关Druid的Servlet 和 Filter的配置粘贴出来。

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; import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter; @Configuration
public class DruidConfig { /**
* 注册一个StatViewServlet
*
* @return servlet registration bean
*/
@Bean
public ServletRegistrationBean druidStatViewServlet() {
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(
new StatViewServlet(), "/druid/*"); servletRegistrationBean.addInitParameter("loginUsername", "admin");
servletRegistrationBean.addInitParameter("loginPassword", "123456");
servletRegistrationBean.addInitParameter("resetEnable", "false");
return servletRegistrationBean;
} /**
* 注册一个:filterRegistrationBean
*
* @return filter registration bean
*/
@Bean
public FilterRegistrationBean druidStatFilter() { FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(
new WebStatFilter()); // 添加过滤规则.
filterRegistrationBean.addUrlPatterns("/*"); // 添加不需要忽略的格式信息.
filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
return filterRegistrationBean;
}
}

以供参考

上一篇:牛客网Java刷题知识点之数组、链表、哈希表、 红黑二叉树


下一篇:listview某一项不可点击