pom文件
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>RELEASE</version>
</dependency>
yml文件
spring:
# 配置数据库信息
datasource:
druid:
# 数据源配置
username: root
password: 123456
url: jdbc:mysql://127.0.0.1:3306/springboot?serverTimezone=GMT%2B8&characterEncoding=UTF-8&useSSL=false # 设置时区
driver-class-name: com.mysql.cj.jdbc.Driver
# 初始化 最小 最大
initial-size: 5
min-idle: 5
max-active: 20
# 配置获取连接等待超时的时间
max-wait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
time-between-eviction-runs-millis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
min-evictable-idle-time-millis: 300000
validation-query: SELECT 'x'
test-while-idle: true