Ron*_*don 0 java mysql spring tomcat8 spring-boot
我已经在 Azure 云中部署了我的 Spring Boot Web 应用程序。使用仅限于 4 个连接的 MySQL 数据库。以下是数据源属性
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
Run Code Online (Sandbox Code Playgroud)
由于我的应用程序丢失了 db 连接并且无法从中恢复,因此我添加了 test-on-borrow 属性。我正在使用 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.
Run Code Online (Sandbox Code Playgroud)
失败的方法
org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection
Run Code Online (Sandbox Code Playgroud)
由于数据源属性而发生错误。通过添加 test-on-borrow 属性,您已指定应验证连接。验证失败,因为查询无效。删除查询上的引号以修复它:
spring.datasource.connection-test-query=SELECT 1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5523 次 |
| 最近记录: |