简体   繁体   English

Spring Boot-Mysql Driver-JPA-服务器运行了很长时间后,发布请求显示无法打开JPA EntityManager进行事务

[英]Spring Boot - Mysql Driver - JPA - After a long time that server is running a post request shows Could not open JPA EntityManager for transaction

I'm using SPRING BOOT application with this configuration: 我正在使用具有此配置的SPRING BOOT应用程序:

pom.xml pom.xml

 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>
 </parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.6</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring4</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>22.0</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>   
</build>

My application.properties has these parameters: 我的application.properties具有以下参数:

mysql.url=jdbc:mysql://localhost:3306/database?autoReconnect=true
mysql.username=root
mysql.password=root
mysql.driver-class-name=com.mysql.cj.jdbc.Driver

When I run the server it works fine. 当我运行服务器时,它工作正常。 Without problems. 没有问题。 But after a time that the Spring Boot server is running, I can see this message when I do a POST request message to any REST service: 但是在运行Spring Boot服务器一段时间后,当我对任何REST服务执行POST请求消息时,我可以看到以下消息:

100   908    0   897  100    11   1741     21 --:--:-- --:--:-- --:--:--  1853{"timestamp":1501411130329,"status":500,"error":"Internal Server Error","exception":"java.lang.IllegalArgumentException","message":"org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 295.677.715 milliseconds ago.  The last packet sent successfully to the server was 295.677.715 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.","path":"/get_last_user"} 

I think that there is an incompatibility with the MySQL driver and the MySQL version defined in pom.xml but I'm not sure. 我认为与pom.xml中定义的MySQL驱动程序和MySQL版本不兼容,但我不确定。

This application is running in DEBIAN 8. I don't know if it is relevant, but I contribute. 该应用程序在DEBIAN 8中运行。我不知道它是否相关,但我贡献了力量。

I don't know if the driver could be com.mysql.jdbc.Driver but it is deprecated. 我不知道驱动程序是否可以是com.mysql.jdbc.Driver,但已弃用。

Thanks in advance. 提前致谢。

Your db connexions may fail after a long time your application started. 您的应用程序启动很长时间后,数据库连接可能会失败。 If you don't want this issue you need to set configuration so that the application restart its connexion automatically. 如果您不希望出现此问题,则需要设置配置,以便应用程序自动重新启动其连接。

In your application.properties, add this : 在您的application.properties中,添加以下内容:

spring.datasource.validationQuery=SELECT 1
spring.datasource.testOnBorrow=true
spring.datasource.max-active=10
spring.datasource.max-idle=5
spring.datasource.min-idle=5
spring.datasource.initial-size=3
spring.datasource.testWhileIdle=true
spring.datasource.max-wait=10000

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法为事务打开JPA EntityManager-通信链接失败(Spring-boot / jpa / hibernate /连接池) - Could not open JPA EntityManager for transaction - Communications link failure (Spring-boot/jpa/hibernate/connection pool) 无法打开JPA EntityManager进行事务处理(使用LocalContainerEntityManagerFactoryBean) - Could not open JPA EntityManager for transaction (using LocalContainerEntityManagerFactoryBean) Spring batch spring jpa 错误 CannotCreateTransactionException: Could not open JPA EntityManager for transaction IllegalStateException: - Spring batch spring jpa error CannotCreateTransactionException: Could not open JPA EntityManager for transaction IllegalStateException: 无法为事务打开 JPA EntityManager; 嵌套异常是 java.lang.NoSuchMethodError - Spring-Starter-JPA - Could not open JPA EntityManager for transaction; nested exception is java.lang.NoSuchMethodError - Spring-Starter-JPA 如何找到 Hibernate + Spring-JPA 的兼容版本对? (无法打开 JPA EntityManager 进行交易) - How to find compatible version pair of Hibernate + Spring-JPA? (Could not open JPA EntityManager for transaction) 无法为事务[...]打开JPA EntityManager。无法为驱动程序类“ null”和URL“ null”获得连接 - Could not open JPA EntityManager for transaction […] A connection could not be obtained for driver class “null” and URL “null” 无法打开JPA EntityManager - Could not open JPA EntityManager Spring Batch无法打开JPA EntityManager进行事务处理; 嵌套异常是java.lang.IllegalStateException:事务已处于活动状态 - Spring Batch Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: Transaction already active Spring Roo JPA MS SQL Server无法打开JPA EntityManager org.hibernate.exception.GenericJDBCException:无法打开连接 - Spring Roo JPA MS SQL Server Could not open JPA EntityManager org.hibernate.exception.GenericJDBCException: Could not open connection 无法打开JPA EntityManager进行交易。 JTA EntityManager不能使用getTransaction() - Could not open JPA EntityManager for transaction. A JTA EntityManager cannot use getTransaction()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM