spring +mybatis系统运行时有时会失去数据库连接,如何处理异常
Mysql服务器默认的“wait_timeout”是8小时,也就是说一个connection空闲超过8个小时,Mysql将自动断开该connection
可以进行配置:
validationQuery = “select 1”
testWhileIdle = “true”
//some positive integer
timeBetweenEvictionRunsMillis = 3600000
//set to something smaller than ‘wait_timeout’
minEvictableIdleTimeMillis = 18000000
//if you don’t mind a hit for every getConnection(), set to “true”
testOnBorrow = “true”
<!– 连接检查–>
<property name=”validationQuery” value=”select 1″></property>
<property name=”testOnBorrow” value=”true”></property>
<property name=”testOnReturn” value=”true”></property>
<property name=”testWhileIdle” value=”true”></property>