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

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


Per a senior member in the Spring forums, the Spring DataSource is not intended for production use:

The above answers are only part of the solution. Indeed you need proper transaction managent AND you need a connection pool. The DriverManagerDataSource is NOT meant for production, it opens and closes a datebase connection each time it needs one.

Instead you can use C3P0 as your DataSource which handles the reconnect and is much better in performance. Here's a quick example of a potential configuration in a Spring xml configuration:

<bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"    destroy-method="close">    <property name="driverClass" value="com.mysql.jdbc.Driver" />    <property name="jdbcUrl" value="#{systemProperties.dbhost}" />    <property name="user" value="#{systemProperties.dbuser}" />    <property name="password" value="#{systemProperties.dbpass}" />    <property name="maxPoolSize" value="25" />    <property name="minPoolSize" value="10" />    <property name="maxStatements" value="100" />    <property name="testConnectionOnCheckout" value="true" /></bean><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">    <constructor-arg ref="c3p0DataSource" /></bean>


Spring (3) boot settings for hibernate and oracle:

spring.datasource.test-on-borrow=true

spring.datasource.validation-query=select 1 from dual



Try changing your connection URL to:

spring.datasource.url=jdbc:mysql://localhost/validation?autoReconnect=true