0.用法:
首先找到DruidDataSourceAutoConfigure.java
根据其中四个导入的类,来找到需要的配置,然后配置到yaml文件中
@Import({DruidSpringAopConfiguration.class,
DruidStatViewServletConfiguration.class,
DruidWebStatFilterConfiguration.class,
DruidFilterConfiguration.class})
1.主配置文件
/*application.yml*/
spring:
datasource:
url: jdbc:mysql:///myblog?characterEncoding=utf8&useSSL=false
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 1234
# filters: stat,wall
# max-active: 12
druid:
stat-view-servlet: #监控页配置
enabled: true
login-username: admin
login-password: 12345
reset-enable: false
web-stat-filter: #监控web应用
enabled: true
url-pattern: /*
exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*'
aop-patterns: com.atguigu.admin.* #spring监控
filters: stat,wall,slf4j #配置sql监控、防火墙、日志
filter: #对上面filter里面的详细配置
stat:
log-slow-sql: true #是否记录慢查询
slow-sql-millis: 1000
enabled: true
wall:
enabled: true
config:
drop-table-allow: false #拦截删表操作
jdbc:
template:
query-timeout: 3