错误:NotSerializableException: org.apache.struts2.dispatcher.StrutsRequestWrapper

当运行ssh项目时,tomcat重启动时,报如下的错误:

严重: IOException while loading persisted sessions: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.struts2.dispatcher.StrutsRequestWrapper
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.struts2.dispatcher.StrutsRequestWrapper
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1331)
	at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1969)
	at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1893)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1775)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1327)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
	at org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1441)
	at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:942)
	at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:394)
	at org.apache.catalina.session.StandardManager.load(StandardManager.java:321)
	at org.apache.catalina.session.StandardManager.start(StandardManager.java:637)
	at org.apache.catalina.core.ContainerBase.setManager(ContainerBase.java:438)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4271)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
	at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
	at org.apache.catalina.core.StandardService.start(StandardService.java:516)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.io.NotSerializableException: org.apache.struts2.dispatcher.StrutsRequestWrapper
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1483)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
	at org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1517)
	at org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:959)
	at org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:517)
	at org.apache.catalina.session.StandardManager.unload(StandardManager.java:463)
	at org.apache.catalina.session.StandardManager.stop(StandardManager.java:667)
	at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4519)
	at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:924)
	at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:1191)
	at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:1162)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:313)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1086)
	at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1098)
	at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:448)
	at org.apache.catalina.core.StandardService.stop(StandardService.java:584)
	at org.apache.catalina.core.StandardServer.stop(StandardServer.java:744)
	at org.apache.catalina.startup.Catalina.stop(Catalina.java:628)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:603)
	... 6 more

 但先关闭tomcat后,启动,却不会报错,在网上查了一些资料,原因归结为把未序列化的对象放在了session中,tomcat停止时,会保存session资源,然后再重启服务器后,tomcat会尝试恢复这些session

 

下面一句话是关键:“如果对象被保存在了Session中,tomcat在重启时要把Session对象序列化到硬盘,这个对象就必须实现Serializable接口”,如果不懂序列化,可以百度一下,看到后你就会知道为什么放在session中的类都需要序列化了。

 

解决方法

方案一:将放在session中的类实现Serializable接口

方案二(在网上找的,建议方案一):

配置tomcat在关闭的时候就不去保存session资源。

 

 在server.xml中Context下添加如下的内容:



 

再进行启动停止等操作,报如下的类似错误:

 org.apache.catalina.session.PersistentManagerBase start

严重: No Store configured, persistence disabled

 

原因是添加的东东少添加了一点点儿。

解决办法:

修改刚才添加的  元素:

将

    

改为:

    

        

    

即可解决该问题。   

 最后一个疑问,为什么tomcat停止时,要保存这些session呢?google之大致原因是,用户访问过后浏览器没有关闭,此时tomcat如果重启,用户访问存在session中的信息就应该还在,所以session要将对象信息序列化到硬盘,重启时再反序列化到session中。这样保证不影响用户的操作。

你可能感兴趣的:(SSH)