org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 2,431 milliseconds ago. The last packet sent successfully to the server was 2,417 milliseconds ago.
### The error may exist in com/melodyhub/mapper/UserMapper.xml
### The error may involve com.melodyhub.mapper.UserMapper.selectUser
### The error occurred while executing a query
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 2,431 milliseconds ago. The last packet sent successfully to the server was 2,417 milliseconds ago.
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
解决:
是mysql超时设置的问题
如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接。
在connection url
中加参数: autoReconnect=true
jdbc.url=jdbc:mysql://localhost:3306/database?autoReconnect=true&autoReconnectForPools=true