Chinaunix首页 | 论坛 | 博客
  • 博客访问: 382480
  • 博文数量: 80
  • 博客积分: 2682
  • 博客等级: 少校
  • 技术积分: 907
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-16 09:55
文章分类

全部博文(80)

文章存档

2012年(80)

分类: 系统运维

2012-12-12 12:54:51

java.io.NotSerializableException 错误解决方法


在重启Tomcat 5时发现报此错误.
查阅后发现tomcat 5之后重启服务后tomcat会尝试恢复session.


解决方法:


方法一(通过配置,使tomcat重启后不重新恢复session):
在 关闭和重启Tomcat 5时, tomcat 会试图 serialize存在的session资源. 如果 sessions中相关的对象没有实现 serializable 接口, 就会出现Cannot serialize session attribute XXX for 异常

java.io.NotSerializableException: ...........
如果你不想看到该异常, 也不想保存session. 那么你可以在项目部署描述文件中(如. test.xml,)(instead of just exploding the war) 的    tags中间 加上 :
saveOnRestart="false">
      


Manager元素可以嵌套在Context组件中。如果不包含它,会自动创建一个缺省的Manager配置,这对大多数需求都是足够的。
详见Tomcat服务器配置参考
http://www.cnjsp.org/document/user/tuman/manager.html

这样 tomcat 在关闭的时候就不会保存session资源了.

你也可以在server.xml中指定上面的值. 这也所有的程序都使用这个设置了.


方法二:
既然报没有序列化的错误,那我们就把我们的对象序列化了就是了,实现起来也很简单,就是把要放入session的对象序列化即可
public class YourClassName implements java.io.Serializable{
}
其他内容都完全不需要变.



警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:lombozweb' did not find a matching property.

The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: c:\Program Files\Java\jdk1.5.0_06\bin;.;C:\WINDOWS\system32;C:\WINDOWS;D:/study tools/Java/jdk1.5.0_06/bin/../jre/bin/client

在网上查找答案,有的说将Tomcat的版本换成6.0.14就可以了;还有的说在建立Dynamic Web Project时把"Dynamic Web Module"选项后面的版本号由2.5改成2.4也行。不过这些回答好像都不能真正地解决问题。


出现SetPropertiesRule警告的原因是因为Tomcat在server.xml的Context节点中不支持source属性:

    

解决方法是在Servers视图里双击创建的server,然后在其server的配置界面中选中"Publish module contexts to separate XML files"选项。


具体“Publish module contexts to separate XML files”是什么意思,

请看Tomcat Publishing Options介绍:
Two new options which affect publishing are now available in the Server Options section of the Tomcat server editor. The Tomcat server must be 5.0.x or later for these options to be enabled. The Serve modules without publishing option does what it says. Web content will be served directly from the "WebContent" folder of the Dynamic Web Project. A customized context is used to make the project's dependencies available in the Web application's classloader. The Publish module contexts to separate XML files option will publish contexts using the preferred method of separate XML files under the "conf/Catalina/localhost" directory, rather than keeping them in the "server.xml" file. A couple of improvements for this option are noted in Bugs 180931 and 180936.




阅读(1393) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~