SpringBoot-整合Druid连接池

 

.yml 格式配置

  # 数据库配置(务必根据实际情况修改配置)
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false
    username: root
    password: 123456
    # 设置连接池为Druid
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      # 初始化大小,最大,最小
      initial-size: 5
      max-active: 20
      min-idle: 5
      # 配置获取连接等待超时的时间
      max-wait: 60000
      # 配置PSCache,指定每个连接上 PSCache 的大小
      pool-prepared-statements: false
      max-pool-prepared-statement-per-connection-size: 20
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位毫秒
      time-between-eviction-runs-millis: 60000
      # 配置一个连接在池中最大,最小生存时间
      max-evictable-idle-time-millis: 300000
      min-evictable-idle-time-millis: 60000
      validation-query: SELECT 1 FROM
      validation-query-timeout: 60000
      test-while-idle: true
      test-on-borrow: false
      test-on-return: false
      # 配置多个英文逗号分隔
      filters: stat,log4j2,slf4j
      # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
      connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000

.properties格式配置

# 数据库配置(务必根据实际情况修改配置)
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
# 设置连接池为Druid
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
# 初始化大小,最小,最大
spring.datasource.druid.initial-size=5
spring.datasource.druid.max-active=5
spring.datasource.druid.min-idle=20
# 配置获取连接等待超时的时间
spring.datasource.druid.max-wait=60000
# 配置PSCache,指定每个连接上 PSCache 的大小
spring.datasource.druid.pool-prepared-statements=false
spring.datasource.druid.max-pool-prepared-statement-per-connection-size=20
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位毫秒
spring.datasource.druid.time-between-eviction-runs-millis=60000
# 配置一个连接在池中最小,最大生存时间
spring.datasource.druid.min-evictable-idle-time-millis=60000
spring.datasource.druid.max-evictable-idle-time-millis=300000
spring.datasource.druid.validation-query=SELECT 1 FROM
spring.datasource.druid.validation-query-timeout=60000
spring.datasource.druid.test-while-idle=true
spring.datasource.druid.test-on-borrow=false
spring.datasource.druid.test-on-return=false
# 配置多个英文逗号分隔
spring.datasource.druid.filters=stat,log4j2,slf4j
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
spring.datasource.druid.connection-properties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
posted @ 2020-04-26 18:03  Git_Bug  阅读(1157)  评论(0编辑  收藏  举报