繁体   English   中英

Spring Boot无法验证新建立的连接

[英]Spring boot Failed to validate a newly established connection

我已经在Azure云中部署了Spring Boot Web应用程序。 使用仅限于4个连接的MySQL DB。 以下是数据源属性

spring.datasource.url=jdbc:mysql://hostname:3306/dbname
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.max-active=4
spring.datasource.connection-test-query="SELECT 1"
spring.datasource.test-while-idle=true
spring.datasource.test-on-borrow=true

由于我的应用失去了数据库连接并且无法从中恢复,因此我添加了“借阅测试”属性。 我正在使用JDBCTemplate。

我经常收到以下异常,但该应用程序仍然可以正常工作。 我需要知道此异常是由于数据源属性还是由于数量有限的connection(4)。 如果我增加连接,该异常将消失。

异常消息

Could not get JDBC Connection; nested exception is java.sql.SQLException: Failed to validate a newly established connection.Failed to validate a newly established connection.

失败的方法

org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection

由于数据源属性,发生了错误。 通过添加“借用测试”属性,您已指定应验证连接。 验证失败,因为查询无效。 删除查询中的引号以解决此问题:

spring.datasource.connection-test-query=SELECT 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM