Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring boot无法验证新建立的连接_Java_Mysql_Spring_Spring Boot_Tomcat8 - Fatal编程技术网

Java Spring boot无法验证新建立的连接

Java Spring boot无法验证新建立的连接,java,mysql,spring,spring-boot,tomcat8,Java,Mysql,Spring,Spring Boot,Tomcat8,我已经在Azure云中部署了我的Spring Boot web应用程序。使用MySQL数据库,该数据库仅限于4个连接。以下是数据源属性 spring.datasource.url=jdbc:mysql://hostname:3306/dbname spring.datasource.username=username spring.datasource.password=password spring.datasource.max-active=4 spring.datasource.conne

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

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

我经常遇到以下异常,但应用程序仍然可以正常工作。我需要知道这个异常是因为数据源属性还是连接数量有限(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

由于数据源属性的原因,正在发生错误。通过添加对借用属性的测试,您已指定应验证连接。验证失败,因为查询无效。删除查询上的引号以修复它:

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

我将spring.datasource.connection-test-query替换为spring.datasource.validation-query,并将值设置为spring.datasource.validation-query=SELECT 1。现在没有任何异常我将spring.datasource.connection-test-query替换为spring.datasource.validation-query,并将值设置为spring.datasource.validation-query=SELECT 1。现在没有任何例外