当前位置: 代码迷 >> 综合 >> jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
  详细解决方案

jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

热度:95   发布时间:2023-11-29 20:33:06.0

这几日一直在调试我的老古董SSM毕业项目,之前本地调试没有问题,然后部署到远程服务器上就出现问题了,而且偶尔还能正常.......

报错信息如下:

Type 异常报告消息 Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.描述 服务器遇到一个意外的情况,阻止它完成请求。Exceptionorg.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)javax.servlet.http.HttpServlet.service(HttpServlet.java:634)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)javax.servlet.http.HttpServlet.service(HttpServlet.java:741)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)Root Causeorg.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:245)org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:457)org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:276)org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)com.sun.proxy.$Proxy135.getTaskByKeysNoState(Unknown Source)com.ssm.controller.TaskController.findtask(TaskController.java:350)java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.base/java.lang.reflect.Method.invoke(Method.java:567)org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:177)org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)javax.servlet.http.HttpServlet.service(HttpServlet.java:634)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)javax.servlet.http.HttpServlet.service(HttpServlet.java:741)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)Root Causecom.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)com.mysql.jdbc.Util.handleNewInstance(Util.java:411)com.mysql.jdbc.Util.getInstance(Util.java:386)com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1251)com.mysql.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:1243)com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4984)org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:371)org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:328)org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:225)org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:457)org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:276)org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)com.sun.proxy.$Proxy135.getTaskByKeysNoState(Unknown Source)com.ssm.controller.TaskController.findtask(TaskController.java:350)java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.base/java.lang.reflect.Method.invoke(Method.java:567)org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:177)org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)javax.servlet.http.HttpServlet.service(HttpServlet.java:634)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)javax.servlet.http.HttpServlet.service(HttpServlet.java:741)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)Root Causecom.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 852,195,331 milliseconds ago.  The last packet sent successfully to the server was 852,195,331 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.java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)com.mysql.jdbc.Util.handleNewInstance(Util.java:411)com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3851)com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2471)com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2677)com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2627)com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1556)com.mysql.jdbc.DatabaseMetaData.getUserName(DatabaseMetaData.java:6760)org.apache.commons.dbcp.DelegatingConnection.toString(DelegatingConnection.java:123)org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.toString(PoolingDataSource.java:355)java.base/java.lang.String.valueOf(String.java:3042)java.base/java.lang.StringBuilder.append(StringBuilder.java:168)org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:206)org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:457)org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:276)org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)com.sun.proxy.$Proxy135.getTaskByKeysNoState(Unknown Source)com.ssm.controller.TaskController.findtask(TaskController.java:350)java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.base/java.lang.reflect.Method.invoke(Method.java:567)org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:177)org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)javax.servlet.http.HttpServlet.service(HttpServlet.java:634)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)javax.servlet.http.HttpServlet.service(HttpServlet.java:741)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)Root Causejava.net.SocketException: Broken pipe (Write failed)java.base/java.net.SocketOutputStream.socketWrite0(Native Method)java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:110)java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:150)java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:81)java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:142)com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3832)com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2471)com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2677)com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2627)com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1556)com.mysql.jdbc.DatabaseMetaData.getUserName(DatabaseMetaData.java:6760)org.apache.commons.dbcp.DelegatingConnection.toString(DelegatingConnection.java:123)org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.toString(PoolingDataSource.java:355)java.base/java.lang.String.valueOf(String.java:3042)java.base/java.lang.StringBuilder.append(StringBuilder.java:168)org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:206)org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:457)org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:276)org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)com.sun.proxy.$Proxy135.getTaskByKeysNoState(Unknown Source)com.ssm.controller.TaskController.findtask(TaskController.java:350)java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.base/java.lang.reflect.Method.invoke(Method.java:567)org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:177)org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)javax.servlet.http.HttpServlet.service(HttpServlet.java:634)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)javax.servlet.http.HttpServlet.service(HttpServlet.java:741)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)Note 主要问题的全部 stack 信息可以在 server logs 里查看

排查方式可以肯定不是代码逻辑问题,报错信息说的是远程数据库连接不上,也就是说数据库拒绝连接请求。后来我发现我远程数据库使用的是5.7版本的,可能我的数据库驱动的问题

我回到我的项目里看了一下我的数据库驱动,发现好久以前导入的数据库驱动使用的是2016就已经停止维护的驱动版本

接着我去maven仓库下载了比较新的jar

然后重新启动

  相关解决方案