SpringBoot使用DruidDataSource 数据源连接MySQL数据库

一、添加依赖



    com.alibaba
    druid-spring-boot-starter
    1.1.10




    mysql
    mysql-connector-java
    runtime

二、配置application.properties

### datasource相关配置
spring.datasource.druid.db-type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver=com.mysql.jdbc.Driver
spring.datasource.druid.url=jdbc:mysql://127.0.0.1:3306/springboot_test?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
spring.datasource.druid.username=root
spring.datasource.druid.password=root
#连接池配置
spring.datasource.druid.initial-size=5
spring.datasource.druid.min-idle=5
spring.datasource.druid.max-active=20
#连接等待超时时间
spring.datasource.druid.max-wait=30000
#配置监测可以关闭的空闲连接间隔时间
spring.datasource.druid.time-between-eviction-runs-millis=60000
# 配置连接在池中的最小生存时间
spring.datasource.druid.min-evictable-idle-time-millis=300000
spring.datasource.druid.filter.stat.log-slow-sql=true

 

你可能感兴趣的:(SpringBoot)