Spring JPA boot check not working

I am currently debugging a small application that is created using spring boot (1.1.2.Release). I had a problem reconnecting to the database if the connection is lost (due to wait_timeout during production or as a result of connecting to the connection). I am currently using the following configuration options (application.properties):

spring.datasource.url=jdbc:mysql://localhost:3306/test?autoreconnect=true spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.test-on-borrow=true spring.datasource.test-while-idle=true spring.datasource.validation-query=SELECT 1; spring.datasource.initial-size=2 ... username+pw spring.jpa.generate-ddl=true spring.jpa.show-sql=true 

This leads to the following data source:

 org.apache.tomcat.jdbc.pool.DataSource@73e369e5 {ConnectionPool[ defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=com.mysql.jdbc.Driver; maxActive=100; maxIdle=100; minIdle=10; initialSize=2; maxWait=30000; testOnBorrow=true; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=true; testOnConnect=false; password=********; url=jdbc:mysql://localhost:3306/test?autoreconnect=true; username=test; validationQuery=SELECT 1; ; validationQueryTimeout=-1; validatorClassName=null; validationInterval=30000; accessToUnderlyingConnectionAllowed=true; removeAbandoned=false; removeAbandonedTimeout=60; logAbandoned=false; connectionProperties=null; initSQL=null; jdbcInterceptors=null; jmxEnabled=true; fairQueue=true; useEquals=true; abandonWhenPercentageFull=0; maxAge=0; useLock=false; dataSource=null; dataSourceJNDI=null; suspectTimeout=0; alternateUsernameAllowed=false; commitOnReturn=false; rollbackOnReturn=false; useDisposableConnectionFacade=true; logValidationErrors=false; propagateInterruptState=false; ignoreExceptionOnPreLoad=false; } 

My problem is that when the connection is lost, it takes some time until the connection is restored. At the same time, users receive a blank page, and exceptions are thrown on the server side. In my understanding, testOnBorrow should check the connection every time before it is used, and testWhileIdle every 30 seconds. But this is no coincidence. When I look at mysql, it seems like something happens every 35 seconds and the sleep time is reset, but I don't see any requests in the application log. Validation requests seem to be completely absent.

I am accessing the database through spring data repositories.

I currently have no other ideas to try.

+6
source share
1 answer

Try replacing HikariCP instead of tomcat for the connection pool, as it seems to handle timeouts / connection loss much better . Spring Boot will auto-configure HikariCP if it is present in the classpath, but tomcat-jdbc will not.

+1
source

Source: https://habr.com/ru/post/971350/


All Articles