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
