1、报错如下图: 2、配置如下:
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: 123123
password: 123123
initial-size: 10
max-active: 100
min-idle: 10
max-wait: 60000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
#Oracle需要打开注释
#validation-query: SELECT 1 FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
stat-view-servlet:
enabled: true
url-pattern: /druid/*
filter:
stat:
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: false
wall:
config:
multi-statement-allow: true
3、判断规则如下:
- deny优先于allow,如果在deny列表中,就算在allow列表中,也会被拒绝。
- 如果allow没有配置或者为空,则允许所有访问
4、解决步骤如下:
1)、只允许项目部署的那台机器可以访问连接池监控
- spring.datasource.druid.stat-view-servlet.allow=127.0.0.1
2)、设置多个ip可以访问连接池监控 ,需要用 逗号分开
- spring.datasource.druid.stat-view-servlet.allow=192.168.0.1,192.168.0.2
5、再次运行访问Druid控制台,效果如下: