java 在 Tomcat 6.0 上加载持久会话时出现 IOException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14454353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 16:19:28  来源:igfitidea点击:

IOException while loading persisted sessions on Tomcat 6.0

javaspringtomcat

提问by Jyotirup

We have an application in flex which is deployed on load balanced Tomcat 6.0 (There is a load balancer which is passing the request to 2 tomcat servers).

我们在 flex 中有一个应用程序,它部署在负载平衡的 Tomcat 6.0 上(有一个负载平衡器将请求传递给 2 个 tomcat 服务器)。

We are getting a 404 error while access the application. On digging through the tomat logs we found the following error

我们在访问应用程序时收到 404 错误。在挖掘 tomat 日志时,我们发现了以下错误

Log Trace

日志跟踪

2013-01-17 10:42:54,148 org.apache.catalina.session.ManagerBase - IOException while loading persisted sessions: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: bean.Login
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: bean.Login
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1332)
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
..
2013-01-17 10:43:04,135 org.apache.catalina.session.ManagerBase - Exception loading sessions from persistent storage
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: bean.Login
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1332)
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
…
Caused by: java.io.NotSerializableException: bean.Login
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)

Cause

原因

Possible reason for this error is Tomcat tries to serialize the full object graph of all active sessions when you shut it down, and then it tries to restore them when you start it back up. The crux of this is that Tomcat uses "normal" java object serialization, which requires all objects to be Serializable.

此错误的可能原因是 Tomcat 尝试在您关闭时序列化所有活动会话的完整对象图,然后在您重新启动时尝试恢复它们。关键是Tomcat使用了“普通”的java对象序列化,它要求所有的对象都是Serializable。

We have mapped the Login bean in Spring as following

我们在 Spring 中映射了 Login bean,如下所示

<bean id="currLogin" class="bean.Login" scope="session">
      <aop:scoped-proxy />
</bean>

Remedy

补救

Short Term

短期

  • Delete the file session.ser in the catalina_home/work directory
  • Restart the tomcat servers
  • 删除catalina_home/work目录下的session.ser文件
  • 重启tomcat服务器

we are able to login to the application without the error after bouncing the server.

我们能够在弹跳服务器后登录应用程序而不会出现错误。

Long Term

长期

  • Make bean.Login serializable by implementing the Serializable interface.
  • Don't have Tomcat serializing sessions (add to the context.xml, either in the app or in the global tomcat context.xml in the conf/ directory, inside the element.
  • 通过实现 Serializable 接口使 bean.Login 可序列化。
  • 不要让 Tomcat 序列化会话(添加到 context.xml,无论是在应用程序中还是在 conf/ 目录中的全局 tomcat context.xml 中,元素内。

Please let us know the approach to resolve this issue?

请告诉我们解决此问题的方法?

回答by cowls

I believe if you want Tomcat to persist objects in Session between restarts you will need to implement the Serializableinterface. Pretty much you have answered your own question.

我相信如果您希望 Tomcat 在重新启动之间将对象持久保存在 Session 中,您将需要实现该Serializable接口。几乎你已经回答了你自己的问题。

It is up to you whether you want them persisted between restarts or not.

您是否希望它们在重新启动之间持续存在取决于您。