我是 Spring Boot 新手,所以对 application.properties 或 pom.xml 中的配置了解不多。我正在尝试在 Azure VM 中托管的 MySQL DB 中执行 CRUD 操作。一旦我启动我的 spring-boot 应用程序并执行数据库操作,它第一次就可以正常工作。过了一段时间,比如 4-5 分钟,当执行另一个操作时,springboot 应用程序无法连接到数据库并抛出异常。
PSB日志:
2019-12-23 14:43:00.063 DEBUG 64148 --- [http-nio-4400-exec-5] o.s.web.servlet.DispatcherServlet : GET "/rest/path/getFrequentDetail?queryParam1=value1&queryParam2=value2", parameters={masked}
2019-12-23 14:43:00.063 DEBUG 64148 --- [http-nio-4400-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.http.ResponseEntity<com.bla.bla> com.bla.bla(java.lang.String,java.lang.String) throws java.io.IOException
2019-12-23 14:43:00.064 DEBUG 64148 --- [http-nio-4400-exec-5] o.h.e.t.internal.TransactionImpl : On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2019-12-23 14:43:00.064 DEBUG 64148 --- [http-nio-4400-exec-5] o.h.e.t.internal.TransactionImpl : begin
2019-12-23 14:43:05.073 WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@503a164d (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:10.077 WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@56e33182 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:15.079 WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@43689c2d (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:20.082 WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@306934d0 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:25.085 WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@7754c08f (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:30.087 WARN 64148 --- [http-nio-4400-exec-5] com.zaxxer.hikari.pool.PoolBase : HikariPool-2 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@3a33fdce (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.
2019-12-23 14:43:30.091 DEBUG 64148 --- [http-nio-4400-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper : Unable to acquire JDBC Connection [n/a]
java.sql.SQLTransientConnectionException: HikariPool-2 - Connection is not available, request timed out after 30024ms.
at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:697)
应用程序属性
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# Hikari parameters
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.maxLifetime=1800000
spring.datasource.initialize=true
spring.datasource.schema=classpath:schema.sql
spring.batch.initialize-schema=ALWAYS
spring.batch.job.enabled: false
我在互联网上搜索过类似的问题,主要与连接保持打开或 MySQL 超时配置有关。在我的情况下,这两个似乎都很好。
所有操作均使用 JPA 完成。mysql中的超时时间相当高:
- innodb_lock_wait_timeout 50
- 等待超时 28800
- mysqlx_wait_timeout 28800
请帮忙。