接口报错
The last packet sent successfully to the server was 964,698 milliseconds ago.
is longer than the server configured value of ‘wait_timeout’.
You should consider either expiring and/or testing connection validity before use in your application,
increasing the server configured values for client timeouts,
or using the Connector/J connection property ‘autoReconnect=true’ to avoid this problem.;
配置信息
1)使用druid连接池
2)wait_timeout=300(禁止修改)
3)连接已配置autoReconnect=true
解决方案
新增DruidDataSource配置项
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setValidationQuery("select 1");
druidDataSource.setTestWhileIdle(true);
return druidDataSource;
Druid参数说明
validationQuery = “SELECT 1”
#验证连接是否可用,使用的SQL语句
testWhileIdle = “true”
#指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除.
每30秒,取出3条连接(默认值)使用validationQuery = “SELECT 1” 中的SQL进行测试 ,测试不成功就销毁连接。销毁连接后,连接数量就少了,如果小于minIdle数量,就新建连接。