1)Druid简介:(为监控而生的数据库连接池)
Druid是阿里开源的一个JDBC组件库,包含数据库连接池、SQL Parser 等组件。
github参考文档:druid常见问题
2)springboot集成Druid
2.1)在 Spring Boot 项目中加入druid-spring-boot-starter
依赖 (版本看情况而定)
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.17</version>
</dependency>
2.2)添加数据源配置(yml方式)
druid: #自定义数据,用来登录druid页面使用的
username: panda
password: panda
spring:
datasource:
blade:
url: jdbc:mysql://localhost:3306/blade?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
initial-size: 5
max-active: 100
min-idle: 5
max-wait: 60000
max-pool-prepared-statement-per-connection-size: 20
test-on-borrow: false
test-on-return: false
test-while-idle: true
time-between-eviction-runs-millis: 2000
min-evictable-idle-time-millis: 600000
max-evictable-idle-time-millis: 900000
filters: stat #这个不设置的话,在druid管理界面中的SQL监控,是看不到数据的
filter:
stat:
enabled: true
db-type: mysql
log-slow-sql: true
slow-sql-millis: 2000
panda:
url: jdbc:mysql://localhost:3306/panda?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
initial-size: 5
max-active: 100
min-idle: 5
max-wait: 60000
max-pool-prepared-statement-per-connection-size: 20
test-on-borrow: false
test-on-return: false
test-while-idle: true
time-between-eviction-runs-millis: 2000
min-evictable-idle-time-millis: 600000
max-evictable-idle-time-millis: 900000
filters: stat
filter:
stat:
enabled: true
db-type: mysql
log-slow-sql: true
slow-sql-mill