1. 配置Druid
读音(Dzu::id),也读作德鲁伊
(1) 导入pom
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.17</version>
</dependency>
(2) yml配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://39.100.144.125:3306/hospital-test?autoReconnect=true &useSSL=false &serverTimezone=GMT%2B8 &useUnicode=true&characterEncoding=UTF-8
username: root
password: cpsmysql
#从这下面开始复制
druid:
#开启监控页面
stat-view-servlet:
enabled: true
url-pattern: '/druid/*'
#是否可以重置统计页面
reset-enable: false
#控制台管理用户
# login-username: yang
# login-password: test
#开启sql监控
web-stat-filter:
#添加过滤规则
url-pattern: '/*'
#排除一些不必要的url
exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*'
enabled: true
#配置profileEnable能够监控单个url调用的sql列表
profile-enable: true
#session统计功能
session-stat-enable: true
filter:
#sql监控,不开这个sql信息出不来
stat:
enabled: true
log-slow-sql: true
slow-sql-millis: 1000
#防止sql注入的
wall:
enabled: false
不过目前好用的配置:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://39.100.144.125:3306/hospital-test?autoReconnect=true &useSSL=false &serverTimezone=GMT%2B8 &useUnicode=true&characterEncoding=UTF-8
username: root
password: 9DZElav^Hf6$qS%2
druid:
stat-view-servlet:
enabled: true
allow:
deny:
(3) 访问
(4) 官方文档
https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter
https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98