Tomcat 抛出 Cannot serialize session attribute 异常

今天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中指定上面的值. 这也所有的程序都使用这个设置了.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值