進階配置Druid
1、引入Druid依賴
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.13</version>
</dependency>
2、Druid全局配置
spring:
datasource:
username: root
password: 123456
#使用MySQL連接配接驅動8.0以上版本,需要在url後面加上時區設定,GMT%2B8代表中國時區
url: jdbc:mysql://localhost:3306/caiyuanzi?serverTimezone=GMT%2B8
#新版本驅動包,使用com.mysql.cj.jdbc.Driver
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
# 資料源其他配置
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
# 配置監控統計攔截的filters,去掉後監控界面sql無法統計,'wall'用于防火牆
filters: stat,wall,logback
maxPoolPreparedStatementPerConnectionSize: 20
useGlobalDataSourceStat: true
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
3、自定義配置類,将配置中的屬性與DruidDataSource屬性綁定
配置Druid監控