Use jdbc to connect to MySQL. If the connection fails, a similar error may be reported:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 84,371,623 millionseconds ago.
The last packet sent successfully to the server was 78,860,631 millionseconds ago. is longer than the server configured value of 'wait_timeout'.
You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
If the error prompts, you can add autoReconnect=true to the connected url to solve the problem.
It should be noted that the autoReconnect configuration is not recommended for mysql, because if SQLException is not properly handled, it will bring some side effects of data consistency. You can refer to the autoReconect section in https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html.
Spring boot 1.4+ depends on what database connection pool library is used. The supported connection pools include: tomcat, hikari, dbcp (1.5+ abandoned), dbcp2.
tomcat
spring.datasource.tomcat.test-on-borrow=truespring.datasource.tomcat.validation-query=SELECT 1
dbcp2
spring.datasource.dbcp2.test-on-borrow=truespring.datasource.dbcp2.validation-query=SELECT 1
Summarize
The above is the operation method for configuring MySQL database reconnection in Spring Boot introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!