Spring   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了mysql – Spring Boot JPA连接验证不起作用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我目前正在调试一个使用spring boot(1.1.2.ReleasE)构建的小应用程序.如果连接丢失(由于生产中的wait_timeout或开发中的连接被杀),我遇到了重新连接到数据库的问题.我目前正在使用以下配置参数(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

这导致以下数据源:

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;
}

我的问题是,当连接丢失时,需要很长时间才能重新建立连接.同时,用户获得一个页面,并在服务器端抛出异常.根据我的理解,testOnBorrow应该在每次使用前测试连接,每30秒测试一次testWhilEIDle.但事实并非如此.当我看到MysqL时,似乎每隔35秒发生一次事情并且睡眠时间重置,但我在应用程序日志中看不到任何查询.验证查询似乎完全缺失.

我通过spring数据库访问数据库.

我目前没有进一步的想法尝试.

最佳答案
尝试将连接池交换为HikariCP而不是tomcat,因为它似乎处理超时/连接丢失a lot better.如果类路径中存在HikariCP,则Spring Boot将自动配置HikariCP,而tomcat-jdbc不存在.

大佬总结

以上是大佬教程为你收集整理的mysql – Spring Boot JPA连接验证不起作用全部内容,希望文章能够帮你解决mysql – Spring Boot JPA连接验证不起作用所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。