0

我启动tomcat,我的代码运行良好,但有时会发生通信链接故障异常。

org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed:
                at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596)
                at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
                at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
                at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
                at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
                at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
                at tm.dao.user.UserMasterDAO$$EnhancerByCGLIB$$12662d42.getLogin(<generated>)
                at tm.controller.teacher.BasicController.doSignInPOST(BasicController.java:269)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:616)
                at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
                at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
                at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
                at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
                at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
                at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
                at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
                at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
                at java.lang.Thread.run(Thread.java:679)
        Caused by: org.hibernate.TransactionException: JDBC begin failed:
                at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:96)
                at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1353)
                at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:555)
                ... 36 more
        Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

        Last packet sent to the server was 1 ms ago.
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
                at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
                at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
                at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
                at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2985)
                at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2871)
                at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3414)
                at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
                at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
                at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
                at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4874)
                at com.mchange.v2.c3p0.impl.NewProxyConnection.setAutoCommit(NewProxyConnection.java:881)
                at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:91)
                ... 38 more
        Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
                at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2431)
                at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2882)
                ... 46 more`
4

1 回答 1

0

您还没有真正指定您的环境,或显示您的任何配置,但从您的堆栈跟踪中我可以看到您正在使用 Spring。

在您的 spring 配置 xml 文件中,您可能有一个“dataSource”bean 或类似于以下内容的东西:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

尝试将以下属性添加到该 bean:

<property name="validationQuery" value="select 1" />

此属性在此处解释:DBCP 配置

于 2014-05-02T12:59:20.117 回答