mybatis mysql自动连接数据库_myBatis数据库自动断开的解决办法

本文分析了myBatis在使用Spring+SpringMVC+Mysql时遇到数据库自动断开的问题,异常原因是Mysql的'wait_timeout'配置导致。解决方案包括配置数据源的validationQuery、testWhileIdle等参数,以确保连接的有效性。
摘要由CSDN通过智能技术生成

使用Spring+SpringMVC+myBatis+Mysql开发一个应用服务端,由于在测试阶段没有上线,所以没有人会链接服务器。

放假回来才发现数据库被关闭了,而且要重启tomcat才有效,都不知道myBatis为什么会没有自动重连数据库的功能。

异常信息:

23-Sep-2017 09:43:39.880 SEVERE [http-nio-8081-exec-93] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcher] in context with path [/project] threw exception [Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException:

### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

### The error may exist in file [/www/apache-tomcat-8081/webapps/project/WEB-INF/classes/com/test/system/mapper/xml/cateMapper.xml]

### The error may involve com.test.system.mapper.SdGoodsCateMapper.getCateByGroup

### The error occurred while executing a query

### SQL: SELECT b.* FROM …..;

### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

; SQL []; No operations allowed after connection closed.; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.] with root cause

java.net.SocketException: Broken pipe (Write failed)

at java.net.SocketOutputStream.socketWrite0(Native Method)

at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)

at java.net.SocketOutputStream.write(SocketOutputStream.java:155)

at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)

at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)

at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3728)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2509)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2490)<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值