pom.xml
<!-- Druid 数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.23</version>
</dependency>
application.yml
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/spring_boot_demo?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
username: root
password: 123456
druid:
initial-size: 5
min-idle: 1
max-wait: 60000
stat-view-servlet:
# 可视化页面
enabled: true
# 可视化界面用户名
login-username: admin
# 可视化界面密码
login-password: admin
# 可视化界面地址前缀
url-pattern: "/druid/*"
web-stat-filter:
enabled: true
url-pattern: "/*"
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
filter:
stat:
enabled: true
# 数据库类型
db-type: mysql
# 记录慢SQL
log-slow-sql: true
# 默认慢SQL为500ms,这里改成2ms
slow-sql-millis: 2
启动并执行一条SQL后打开监控页面
8080是你的SpringBoot项目端口
http://localhost:8080/druid/index.html
执行一条SQL
打开SQL监控页面查看慢SQL