我遇到了一个关于从Spring Boot应用程序连接到MySQL的问题。部署后几个小时它都可以正常工作。但是当我停止我这边的任何活动(通常是在晚上)时,服务器会崩溃,例外情况如下:
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.TransactionException: JDBC begin transaction failed:
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:431)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:427)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:276)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at com.trammellventures.btd.services.user.UserService$$EnhancerBySpringCGLIB$$7e8f85.getAdminAccount(<generated>)
at com.trammellventures.btd.services.email.EmailCommonService.informAdminAboutTickerDefect(EmailCommonService.java:102)
at com.trammellventures.btd.services.email.EmailCommonService$$FastClassBySpringCGLIB$$bec6b855.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:115)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.persistence.PersistenceException: org.hibernate.TransactionException: JDBC begin transaction failed:
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1771)
at org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:64)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:170)
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380)
... 15 common frames omitted
Caused by: org.hibernate.TransactionException: JDBC begin transaction failed:
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:76)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:162)
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1471)
at org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:61)
... 17 common frames omitted
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
>
The last packet successfully received from the server was 33 715 694 milliseconds ago. The last packet sent successfully to the server was 2 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:981)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3465)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3365)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3805)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2547)
at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4874)
at sun.reflect.GeneratedMethodAccessor127.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:81)
at com.sun.proxy.$Proxy99.setAutoCommit(Unknown Source)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:72)
... 20 common frames omitted
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:100)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:143)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:173)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2954)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3375)
... 34 common frames omitted
我的申请。属性文件非常简单:
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/mydb
spring.datasource.username=test
spring.datasource.password=test
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=none
我想它可以连接到MySQL连接超时(如果我没弄错的话,默认值是8h)。我说得对吗?你能为我提供一些解决这种情况的方法吗?提前谢谢!
您可以尝试添加以下属性以查看连接是否是kepet持久的。
spring.datasource.testWhileIdle = true
spring.datasource.timeBetweenEvictionRunsMillis = 60000
spring.datasource.validationQuery = SELECT 1
看看这是否有助于您连接到Db后死亡
另外,请考虑spring boot 1.4的属性更改日志,以查找spring boot的属性密钥。1.4-Changelog:
spring.datasource.dbcp.test-while-idle=true
spring.datasource.dbcp.time-between-eviction-runs-millis=3600000
spring.datasource.dbcp.validation-query=SELECT 1
所有这些属性及其配置含义都可以在这里找到https://commons.apache.org/proper/commons-dbcp/configuration.html
问题内容: 我正在开发使用JPA + Hibernate访问MySQL数据库的独立服务器。 当我启动服务器时,一切正常。但是,经过一段时间(通常是第二天早上,如果我在下午开始),它将停止工作,因为与MySQL的连接显然已关闭(我在日志中看到很多s)。这可能是由于闲置造成的,服务器正在开发中,晚上没有人使用它。 我以为Hibernate,JDBC或我应用程序下面的其他某些层将管理连接,并在必要时重新
我编写了一些逻辑,同时表示与exchange的近200个websocet连接。我使用第三方api,它基于org.eclipse.jetty.webSocket.api。我有一个我必须重写的方法。 我在stackoverflow上找到了这个问题,但我看不到清晰的答案。请帮忙,提前谢谢。
我有4个Kafka和debezium一起运行。经过几天的良好运行后,三台kafka机器脱离网络一段时间,在< code > connect distributed . out 日志文件中,我收到了许多包含以下错误的消息: 我有4台Kafka机器,经纪人从0到3 动物园管理员: <代码>192.168.240.70 关注我的 - 除了之外,有相同的 指向安装 Kafka 的计算机的相同 IP,并且
我正在构建第一个Node.js应用程序,遇到了MongoDB的问题。我用的是蒙古人的驱动程序。 错误:连接关闭在server.connect.connectionpool.on.server._serverstate(x:\code\codetunnel\node_module\mongoskin\node_module\mongodb\lib\mongodb\connection\server.
重启MySQL后丢失Wildfly连接 我们使用2个版本MySQL版本14.14发行版5.6.51,Linux(x86_64)使用EditLine包装和MySQL版本8.0.28Linuxx86_64(MySQL社区服务器-GPL) 我们尝试了两个版本的Wildfly Wildfly-10.1.0。最终版本和wildfly-19.1.0。最终的 我们使用了JDBC数据库连接器版本is-8.0.19
问题内容: 我的Spring Boot应用程序总是在早上向我显示此whitelabel错误:无法打开JPA EntityManager进行事务;嵌套异常是javax.persistence.PersistenceException:org.hibernate.TransactionException:JDBC开始事务失败: 我在网上搜索,我认为可能是mysql关闭了8个小时的非活动连接。但是,根据