问题
I am getting following stacktrace error while running web application on tomcat, unable to find root cause of this exception.
Eclipse 32 bit Luna Release (4.4.0) Tomcat 32 bit 8.0.30 jdk1.8.0_66
Jan 01, 2016 10:02:16 AM org.apache.catalina.session.StandardManager startInternal
SEVERE: Exception loading sessions from persistent storage
java.lang.ClassCastException: java.io.ObjectStreamClass cannot be cast to java.lang.String
at java.io.ObjectInputStream.readTypeString(ObjectInputStream.java:1419)
at java.io.ObjectStreamClass.readNonProxy(ObjectStreamClass.java:719)
at java.io.ObjectInputStream.readClassDescriptor(ObjectInputStream.java:831)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1602)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at org.apache.catalina.session.StandardSession.doReadObject(StandardSession.java:1627)
at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1090)
at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:261)
at org.apache.catalina.session.StandardManager.load(StandardManager.java:180)
at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:460)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5272)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Jan 01, 2016 10:02:16 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'bgx'
回答1:
I appear to have had the same problem but it was not a bug in Tomcat. It was due to an object belonging to the application being stored in the HTTP Session that was not serializable and which therefore Tomcat was unable to serialize when persisting sessions.
I suggest having a gawk at the contents of Tomcat's persistent sessions storage file: SESSIONS.ser, located in the Tomcat "work" directory for the corresponding Web Application.
Opening this binary file in a Text editor (when Tomcat has shutdown!), the presence of the string java.io.NotSerializableException will identify the serialization issue and the whereabouts in the file should give a clue as to which Object/field Tomcat was unable to serialize when persisting sessions.
回答2:
I have had the same issue. All I did to resolve the issue isis: First stop the tomcat, then right click on it and select Clean to clean the working directory of tomcat. Then I started it again without any errors.
回答3:
I had the same problem. Seems to be a bug in Apache Tomcat 8.0.30 and maybe versions around it.
It worked for me in version 8.0.23 and then 8.5.8 as well.
来源:https://stackoverflow.com/questions/34553583/java-lang-classcastexception-java-io-objectstreamclass-cannot-be-cast-to-java-l