gpt4 book ai didi

java - 无法打开 JPA 实体管理器

转载 作者:行者123 更新时间:2023-11-29 16:08:39 24 4
gpt4 key购买 nike

我正在使用 Spring BOOT 应用程序,它将信息存储在数据库中。我收到错误:

org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction

我尝试在互联网上搜索,但找不到任何答案。当我重新启动我的 jar 时,它工作正常 - 错误不会出现。这种情况每天都会发生,我必须每天重新启动 jar。

Exception : org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 44,382,666 milliseconds ago. The last packet sent successfully to the server was 44,382,666 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

计划每天每十分钟运行一次。

我尝试减少时间段 - 安排在特定时间运行,但仍然没有成功。

还尝试了 autoReconnect=true,在数据库 URL 中提供了端口号。

最佳答案

似乎this is the answer

spring.datasource.testOnBorrow=true
spring.datasource.testWhileIdle = true
spring.datasource.timeBetweenEvictionRunsMillis = 3600000
spring.datasource.validationQuery=SELECT 1

关于java - 无法打开 JPA 实体管理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55501608/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com