加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

mysql – Spring Boot JPA连接验证不起作用

发布时间:2020-12-15 01:29:09 所属栏目:大数据 来源:网络整理
导读:我目前正在调试一个使用spring boot(1.1.2.Release)构建的小应用程序.如果连接丢失(由于生产中的wait_timeout或开发中的连接被杀),我遇到了重新连接到数据库的问题.我目前正在使用以下配置参数(application.properties): spring.datasource.url=jdbc:mysql:

我目前正在调试一个使用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不存在.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读