严重: testWhileIdle is true, validationQuery not set 使用Druid连接池报错处理
环境: JDK8 、MYSQL 5.7.17 、Spring boot 2.1.6 、Druid - 1.1.10 的jar包;
使用 druid-1.1.10.jar 报错如下;
3月 25, 2020 7:55:37 下午 com.alibaba.druid.pool.DruidDataSource error 严重: testWhileIdle is true, validationQuery not set 3月 25, 2020 7:55:50 下午 com.alibaba.druid.pool.DruidDataSource info 信息: {dataSource-1} inited
在properties配置文件下添加一些配置;
filters=stat initialSize=2 maxActive=300 maxWait=60000 timeBetweenEvictionRunsMillis=60000 minEvictableIdleTimeMillis=300000 validationQuery=SELECT 1 testWhileIdle=true testOnBorrow=true testOnReturn=false poolPreparedStatements=false maxPoolPreparedStatementPerConnectionSize=200
完整配置如下:
spring: application: name: test datasource: url: jdbc:mariadb://127.0.0.1:3306/test?characterEncoding=utf-8 driver-class-name: org.mariadb.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource druid: initial-size: 15 min-idle: 15 max-active: 200 max-wait: 60000 time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 300000 validation-query: select 1 test-while-idle: true test-on-borrow: true test-on-return: false pool-prepared-statements: false connection-properties: false filters: stat,slf4j filter: slf4j: connection-log-enabled: false data-source-log-enabled: false result-set-log-enabled: false statement-log-enabled: true web-stat-filter: enabled: false log-abandoned: true remove-abandoned: true remove-abandoned-timeout: 60 keep-alive: true max-pool-prepared-statement-per-connection-size: 10
再次运行;
3月 25, 2020 8:14:13 下午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} inited
报错2;
信息: {dataSource-1} inited
这是日志信息,没有错Druid采用了日志打印机制,这不是报错;
连接池采用了懒加载,真正用到的时候才初始化;