In MySQL database, by default, if a connection is idle for more than 8 hours, the connection will be closed on the database side, and the data source does not know that the connection has been closed by the database, and when this useless connection is given to DAO, an exception is generated.
In spring, if the data source is configured with DBCP
If you are using the default configuration of DBCP, you will not incur a 8-hour problem because each data source will be checked before it is connected to DAO, but this can affect efficiency
A better approach is to:
<BeanID= "Mysql_datasource"class= "Org.apache.commons.dbcp.BasicDataSource"Destroy-method= "Close"P:driverclassname= "${driverclassname}"P:url= "${url}"P:username= "${username_mysql}"P:password= "${password}"P:testonborrow= "false"P:testwhileidle= "true"P:timebetweenevictionrunsmillis= "27000000"P:validationquery= "Select 1"/>
P:timebetweenevictionrunsmillis is less than 8 hours in milliseconds, but this 8 hour can also be configured with the Interactive-timeout parameter in MySQL, so in configuration p: Timebetweenevictionrunsmillis, you need to know the value of the Interactive-timeout setting first
MySQL 8-hour issue