使用必看:https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98

1、pom文件中一定要配置druid

<!-- alibaba的druid数据库连接池 -->
<dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.1.9</version>
</dependency>

2、编写druid filter配置类

package com.mysql.monitor;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 DruidMonitorConfig {/*** 注册ServletRegistrationBean* @return*/@Beanpublic ServletRegistrationBean registrationBean() {ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");//白名单servletRegistrationBean.addInitParameter("allow", "");//多个ip逗号隔开//IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page.//servletRegistrationBean.addInitParameter("deny", "");//登录查看信息的账号密码.servletRegistrationBean.addInitParameter("loginUsername", "admin");servletRegistrationBean.addInitParameter("loginPassword", "admin");//是否能够重置数据.servletRegistrationBean.addInitParameter("resetEnable", "true");return servletRegistrationBean;}/*** 注册FilterRegistrationBean* @return*/@Beanpublic FilterRegistrationBean druidStatFilter() {FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());//添加过滤规则.filterRegistrationBean.addUrlPatterns("/*");//添加不需要忽略的格式信息.filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");return filterRegistrationBean;}
}

3、修改.properties配置文件

########druid监控######################
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙,log4j2:日志
spring.datasource.filters=stat,wall,log4j2
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
##日志配置
# 配置日志输出
spring.datasource.druid.filter.slf4j.enabled=true
spring.datasource.druid.filter.slf4j.statement-create-after-log-enabled=false
spring.datasource.druid.filter.slf4j.statement-close-after-log-enabled=false
spring.datasource.druid.filter.slf4j.result-set-open-after-log-enabled=false
spring.datasource.druid.filter.slf4j.result-set-close-after-log-enabled=false

4、启动项目,访问  http://localhost:8080/druid/sql.html

Springboot2.X项目中添加druid连接池监控相关推荐

  1. spring-boot中使用druid连接池

      最近因为项目的要求,需要在spring-boot中配置druid连接池,数据库是Oracle,并且是多数据源的连接池,特地写下我的配置经历.   用的框架是spring-boot,数据库是orac ...

  2. druid 连接池监控报错 Sorry, you are not permitted to view this page.

    使用Druid连接池的时候,遇到一个奇怪的问题,在本地(localhost)可以直接打开Druid连接池监控,在其他机器上打开会报错: Sorry, you are not permitted to ...

  3. 阿里Druid连接池监控的两个坑

    转载自 注意:阿里Druid连接池监控的两个坑 阿里的Druid大家都知道是最好的连接池,其强大的监控功能是我们追求的重要特性.但在实际情况中也有不少坑,说下最近遇到的一个坑吧! 问题1:不断打印er ...

  4. SSM中使用Druid连接池

    连接池 最原始的数据库使用就是打开一个连接并进行使用,使用过后一定要关闭连接释放资源.由于频繁的打开和关闭连接对jvm包括数据库都有一定的资源负荷,尤其应用压力较大时资源占用比较多容易产生性能问题.由 ...

  5. spring连接jdbc_在Spring JDBC中添加C3PO连接池

    spring连接jdbc 连接池是一种操作,其中系统会预先初始化将来要使用的连接. 这样做是因为在使用时创建连接是一项昂贵的操作. 在这篇文章中,我们将学习如何在Spring JDBC中创建C3P0连 ...

  6. 在Spring JDBC中添加C3PO连接池

    连接池是一种操作,其中系统会预先初始化将来要使用的连接. 这样做是因为在使用时创建连接是一项昂贵的操作. 在本文中,我们将学习如何在Spring JDBC中创建C3P0连接池(某人未使用休眠). Po ...

  7. druid连接池监控

    项目中使用的数据库连接池是阿里开源的druid连接池,经常会有一些场景需要监控和统计数据源.sql的执行情况,因此引入druid提供的监控druid monitor. Druid是一个开源项目,源码托 ...

  8. 注意:阿里Druid连接池监控的两个坑

    image 阿里的Druid大家都知道是最好的连接池,其强大的监控功能是我们追求的重要特性.但在实际情况中也有不少坑,说下最近遇到的一个坑吧! 问题1:不断打印error级别的错误日志 session ...

  9. Druid 连接池 报错 com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

    场景赘述 早晨查看项目前一天的实际运行日志,发现了 一个Springboot项目中的druid 连接池和 mysql 产生了异常信息,重连暂并未对系统产生影响 下面是具体报错信息: com.mysql ...

  10. druid连接池mysql5.7_Spring Boot 使用Druid连接池整合Mybatis-Plus连接Mysql数据库

    一.连接池 在普通的数据库访问程序中,客户程序得到的连接对象是物理连接,调用连接对象的close()方法将关闭连接,而采用连接池技术,客户程序得到的连接对象是连接池中物理连接的一个句柄,调用连接对象的 ...

最新文章

  1. LR学习笔记三 之 界面分析
  2. java int == integer_java int与integer的区别
  3. codeforces 808 E. Selling Souvenirs (dp+二分+思维)
  4. hash redis springboot_Redis常见的工作场景使用实战,Redisson分布式锁的实现
  5. PPT快捷键大全(作分析报告的人有福了)
  6. ggplot2实现分半小提琴图绘制基因表达谱和免疫得分
  7. 基于Spring Cloud微服务化开发平台-Cloud Platform后台管理系统 v3.1.0
  8. 如何更换清华源_树莓派中国软件源
  9. java .jar怎么打开_jar文件怎么打开,小编教你如何打开jar文件
  10. FreeMarker标签使用
  11. paip.支付宝自动反退款器
  12. 为什么现代企业需提高企业敏捷性
  13. JT/T808校验码计算(按字节异或求和)
  14. java zip解压抛出异常,java – ZipFile抛出错误,但ZipInputStream能够解压缩归档
  15. Python小技 不到100行代码制作各种证件照
  16. NCPC2016-A-ArtWork
  17. 微信小程序跳小程序short-link(#小程序://)
  18. Flannel host-gw 和 vxlan
  19. 企业微信开发(自建应用h5)
  20. 数组与数字之间的转换

热门文章

  1. CAN和CAN FD
  2. 基于物联网的智能门锁应用系统设计方案
  3. jsp 之 入门 jsp代码块
  4. 大学excel题库含答案_2017excel试题库附答案.doc
  5. 2017年电力职称计算机考试题,2017年职称计算机考试Excel试题(1)
  6. 干货!Web 网页设计规范
  7. 开关电源(DC/DC)和线性电源(LDO低压差线性稳压器)的区别
  8. 关于静态博客的评论系统
  9. 帝云CMS内容管理系统
  10. 2009年考研数学一解析pdf