无法在第一次尝试连接时打开jpa entitymanager

a5g8bdjr  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(269)

我在azure上有一个javaspring项目,这个项目连接到maria db数据库(另一个主机),
在swagger中,当我执行一个api调用时,返回这个错误(第二次尝试它可以工作,但是10分钟后,第一次再次失败)

Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection

查看日志文件,我看到这个错误

Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@10caecb6 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.

我的配置文件

spring.datasource.url=jdbc:mysql://database
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# HikariCP

spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.pool-name=name-pool
spring.datasource.hikari.max-lifetime=20000
spring.datasource.hikari.idle-timeout=0
spring.datasource.hikari.maximum-pool-size=10

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题