使用jar:compile group: 'com.alibaba', name: 'druid-spring-boot-starter', version: '1.1.5'测试发现重点有两个参数注意:test-while-idle, time-between-eviction-runs-millis

#druid连接池配置
spring:
  datasource:
    db:
      type: com.alibaba.druid.pool.DruidDataSource
      driver-class-name: com.mysql.jdbc.Driver    #高版本使用 com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhsot:3306/db?autoReconnect=true&useSSL=false&failOverReadOnly=false&maxReconnects=10
      username: xxxx
      password: xxxx
    druid:
      max-active: 100                #指定连接池中最大的活跃连接数.
      initial-size: 10               #指定连接的初始值
      min-idle: 10                   #指定必须保持连接的最小值
      max-wait: 60000                #指定连接池等待连接返回的最大等待时间,设置1分钟;默认-1不限时间
      test-on-borrow: false          #获取连接时候验证,会影响性能,默认为false
      test-while-idle: true          #验证连接的有效性
      time-between-eviction-runs-millis: 300000     #空闲连接回收的时间间隔,与test-while-idle一起使用,设置5分钟
      min-evictable-idle-time-millis: 1800000       #连接池空闲连接的有效时间 ,设置30分钟
      validation-query: select 1
      remove-abandoned-timeout: 30   #隔30秒回收断开的连接
      remove-abandoned: true         #当连接超过了removeAbandonedTimout时间,删除泄露的连接,默认false
      log-abandoned: true            #当Statement或连接被泄露时打印程序的stack traces日志
      filter:
        slf4j:
          enabled: true                    #开启slf4j debug日志打印
          statement-log-enabled: false     #关闭statement相关debug日志打印
          result-set-log-enabled: false    #关闭result-set相关debug日志打印

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐