SpringBoot Druid 配置详解
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${url}:${port}/${数据库名}?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&allowMultiQueries=true&useAffectedRows=true
username: ${username}
password: ${password}
druid:
initial-size: 10
min-idle: 10
maxActive: 200
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
connectionErrorRetryAttempts: 3
breakAfterAcquireFailure: true
timeBetweenConnectErrorMillis: 300000
asyncInit: true
remove-abandoned: true
remove-abandoned-timeout: 1800
transaction-query-timeout: 6000
filters: stat,wall,log4j2
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
web-stat-filter:
enabled: true
url-pattern: "/*"
exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
stat-view-servlet:
url-pattern: "/druid/*"
allow:
deny:
reset-enable: false
login-username: admin
login-password: admin
druid监控数据的外部化调用
@RestController
public class DruidStatController {
@GetMapping("/stat")
public Object druidStat() {
return DruidStatManagerFacade.getInstance().getDataSourceStatDataList();
}
}
打开App,阅读手记