天天看点

成功解决: [main] ERROR DruidDataSource:52 - testWhileIdle is true, validationQuery not set(讲解的很详细,很详细)

2020-03-28 18:24:37 [main] ERROR DruidDataSource:52 - testWhileIdle is true, validationQuery not set

成功解决: [main] ERROR DruidDataSource:52 - testWhileIdle is true, validationQuery not set(讲解的很详细,很详细)
成功解决: [main] ERROR DruidDataSource:52 - testWhileIdle is true, validationQuery not set(讲解的很详细,很详细)

项目使用的是ssm框架

解决:在applicationContext.xml 文件,即配置数据库连接池相关的文件,如下图

成功解决: [main] ERROR DruidDataSource:52 - testWhileIdle is true, validationQuery not set(讲解的很详细,很详细)

添加以下信息(主要是最后四个property ):

<property name="filters" value="stat"/>
        <property name="initialSize" value="2"/>
        <property name="maxActive" value="300"/>
        <property name="maxWait" value="60000"/>
        <property name="timeBetweenEvictionRunsMillis" value="60000"/>
        <property name="minEvictableIdleTimeMillis" value="300000"/>
        <property name="poolPreparedStatements" value="false"/>
        <property name="maxPoolPreparedStatementPerConnectionSize" value="200"/>
		<property name="validationQuery" value="select 1"/>
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testOnReturn" value="false"/>
           

如果是properties文件配置数据库连接:

例如:

driverClassName = com.mysql.cj.jdbc.Driver
url = jdbc:mysql:///test?serverTimezone=UTC
username = root
password = root
           

添加如下:

filters=stat
initialSize=2
maxActive=300
maxWait=60000
timeBetweenEvictionRunsMillis=60000
minEvictableIdleTimeMillis=300000
validationQuery=SELECT 1
testWhileIdle=true
testOnBorrow=false
testOnReturn=false
poolPreparedStatements=false
maxPoolPreparedStatementPerConnectionSize=200