Spring is losing connection to the DB and does not recover or reconnect

后端 未结 4 1258
予麋鹿
予麋鹿 2020-12-13 10:15

I have a spring-boot application on the same host as the Maria DB and both are running fine for some time. But between 12 hours and 2 days it seems that the spring boot appl

4条回答
  •  粉色の甜心
    2020-12-13 10:54

    To elaborate on @user5101998's answer and update the other ones, autoReconnect is actually not recommended. From the connector documentation:

    The use of this feature is not recommended, because it has side effects related to session state and data consistency when applications don't handle SQLExceptions properly, and is only designed to be used when you are unable to configure your application to handle SQLExceptions resulting from dead and stale connections properly

    The test-on-borrow property makes your provider (Tomcat, Hikari, etc.) tests that the connection is valid before fetching it from the connection pool.

    The validate-query is what will be used to ensure that the connection is valid.

    Using these parameters should prevent Spring from using dead connections. For Tomcat for instance, you can find documentation here on these parameters.

提交回复
热议问题