springboot整合druid

引入依赖

1
2
3
4
5
6
7
8
9
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.23</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>

配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
spring:
# 数据源配置
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: root
druid:
# druid监控页面
stat-view-servlet:
enabled: true
# url
url-pattern: /druid/*
# 是否可以重置
reset-enable: false
# 登录账号
login-username: root
# 登录密码
login-password: root
# 白名单
allow:
# 黑名单,优先于白名单
deny:
# 统计
web-stat-filter:
enabled: true
# 排除不必要拦截的url
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
# 拦截url
url-pattern: /*
# 关闭session统计功能
session-stat-enable: false
filter:
# 开启防火墙,防sql注入等
wall:
enabled: true
# 开启监控功能
stat:
enabled: true
# 慢sql记录
log-slow-sql: true
# sql合并
merge-sql: true

访问

http://localhost:9000/druid