您的位置:首页 > 运维架构 > Tomcat

Tomcat 抛出 Cannot serialize session attribute 异常

2012-05-16 23:40 441 查看
今天team成员遇到个很奇怪的问题,在启动和关闭Tomcat 6时, 抛出如下异常:Cannot serialize session attribute XXX  for 。我很是纳闷,到apache官网查看了下,发现tomcat 会试图 serialize存在的session资源. 如果 sessions中相关的对象没有实现 serializable 接口, 就会出现Cannot serialize session attribute XXX  for  异常。由于开始对某个类实现了Serializable接口,启动了tomcat,然后又取消实现Serializable接口,重启tomcat就报错了。原文如下:

Because when you shutdown tomcat, it tries to serial all objects within

the session scope.  The

class you are referring to

'org.apache.commons.fileupload.DeferredFileOutputStream' does not

implement 'java.io.Serializable' and therefore tomcat throws this

exception when trying to serialize it.

Whilst I don't know what the class

'org.apache.catalina.session.StandardManager' does, presumably is

performs a check to see if an object stored within the session is

serializable before trying to

write it disk, or it might remove non-serializable object from the

session scope on shutdown.


如果你不想看到该异常, 也不想保存session. 那么你可以在项目部署描述文件中(如. test.xml,)(instead of just exploding the war)  的  <Context> tags中间 加上 :
<Manager className="org.apache.catalina.session.PersistentManager"
saveOnRestart="false"/>这样 tomcat 在关闭的时候就不会保存session资源了.你也可以在server.xml中指定上面的值. 这也所有的程序都使用这个设置了.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐