[英]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.