[工作点滴]定时任务不定期报连接数据库失败

背景:公司所用的开发结构SSM(spring+spinrgMVC+Mybatis),spring 内置了很多的定时任务,于是新开一个项目把后续用到的定时任务单独配置起来

异常描述:经常会出现数据库连接超时。定时任务没跑  进本上都是这种问题。上网搜了一把,好像是mysql连接池中的连接已经expired的问题。试了几种方式,最终通过在MYSQL的JDBC连接串上加了autoReconnectForPools=true解决了

异常代码:

org.springframework.dao.RecoverableDataAccessException: 

### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


The last packet successfully received from the server was 5,903,769 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.

### The error may exist in class path resource [mybatis/ErpWarehouseMapper.xml]

### The error may involve com.tqmall.erp.quartz.dao.ErpWarehouseDao.selectByParam-Inline

### The error occurred while setting parameters

### SQL: 

### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


The last packet successfully received from the server was 5,903,769 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.

; SQL []; Communications link failure


The last packet successfully received from the server was 5,903,769 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


The last packet successfully received from the server was 5,903,769 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.

at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98) ~[erp-quartz.jar:na]

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[erp-quartz.jar:na]

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[erp-quartz.jar:na]

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73) ~[erp-quartz.jar:na]

at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371) ~[erp-quartz.jar:na]

at com.sun.proxy.$Proxy28.selectList(Unknown Source) ~[na:na]

at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198) ~[erp-quartz.jar:na]

at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122) ~[erp-quartz.jar:na]

at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64) ~[erp-quartz.jar:na]

at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) ~[erp-quartz.jar:na]

at com.sun.proxy.$Proxy29.selectByParam(Unknown Source) ~[na:na]


处理方案:数据库连接信息配置后面加 autoReconnectForPools=true(不知道有效果没)






  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值