spring boot整合druid无法监控sql
Posted peterxu1997
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot整合druid无法监控sql相关的知识,希望对你有一定的参考价值。
最近在学习spring boot,然后尝试使用druid进行SQL监控,但是一直没有数据,上网搜了很久
发现,依赖错了
错误依赖:
1 <dependency> 2 <groupId>com.alibaba</groupId> 3 <artifactId>druid-spring-boot-starter</artifactId> 4 <version>1.1.1</version> 5 </dependency>
正确依赖:
1 <dependency> 2 <groupId>com.alibaba</groupId> 3 <artifactId>druid</artifactId> 4 <version>1.0.19</version> 5 </dependency>
最后是配置类:
1 import com.alibaba.druid.support.http.StatViewServlet; 2 import com.alibaba.druid.support.http.WebStatFilter; 3 import org.springframework.boot.web.servlet.FilterRegistrationBean; 4 import org.springframework.boot.web.servlet.ServletRegistrationBean; 5 import org.springframework.context.annotation.Bean; 6 import org.springframework.context.annotation.Configuration; 7 8 9 @Configuration 10 public class DruidConfig { 11 @Bean 12 public ServletRegistrationBean druidServlet() { 13 14 ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*"); 15 //登录查看信息的账号密码. 16 17 servletRegistrationBean.addInitParameter("loginUsername","admin"); 18 19 servletRegistrationBean.addInitParameter("loginPassword","123456"); 20 return servletRegistrationBean; 21 } 22 23 @Bean 24 public FilterRegistrationBean filterRegistrationBean() { 25 FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); 26 filterRegistrationBean.setFilter(new WebStatFilter()); 27 filterRegistrationBean.addUrlPatterns("/*"); 28 filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); 29 return filterRegistrationBean; 30 } 31 }
以上是关于spring boot整合druid无法监控sql的主要内容,如果未能解决你的问题,请参考以下文章
Spring Boot:Spring Boot整合Druid