59

I have made many changes to the spring petclinic application. At the moment, I am getting the following error message when I launch the application in a new instance of tomcat server using eclipse run as...run on server:

SEVERE: Exception loading sessions from persistent storage  

The server and application then subsequently are able to launch successfully, but I would like to fix whatever is causing the error message. Can anyone show me how to get past this error message?

The stack trace does not list any file from the application, so I don't know where to look in the application code to fix the problem. You can look in the petclinic code at github to see the structure of the application, if that helps you see where I should look to find the problem. Here is the stack trace:

INFO  EhCacheManagerFactoryBean - Initializing EhCache CacheManager
INFO  ContextLoader - Root WebApplicationContext: initialization completed in 4376 ms
Dec 16, 2013 2:51:56 PM org.apache.catalina.session.StandardManager doLoad
SEVERE: IOException while loading persisted sessions: java.io.EOFException  
java.io.EOFException
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2280)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2749)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:779)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
    at org.apache.catalina.util.CustomObjectInputStream.<init>(CustomObjectInputStream.java:58)
    at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:246)
    at org.apache.catalina.session.StandardManager.load(StandardManager.java:204)
    at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:491)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Dec 16, 2013 2:51:56 PM org.apache.catalina.session.StandardManager startInternal
SEVERE: Exception loading sessions from persistent storage  
java.io.EOFException
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2280)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2749)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:779)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
    at org.apache.catalina.util.CustomObjectInputStream.<init>(CustomObjectInputStream.java:58)
    at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:246)
    at org.apache.catalina.session.StandardManager.load(StandardManager.java:204)
    at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:491)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Dec 16, 2013 2:51:56 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'petclinic'  
CodeMed
  • 9,527
  • 70
  • 212
  • 364
  • I would guess that this is a mis-match between what is being provided to ehcache and what it is expecting. Have a look at http://ehcache.org/documentation/integrations/hibernate. You could try to turn this off by changing the `true true` – Scary Wombat Dec 17 '13 at 01:57
  • If using Spring configuration the part to change would be `true true` – Scary Wombat Dec 17 '13 at 01:58

8 Answers8

129

This is to do with Tomcat not being able to load previously serialized web sessions that had been saved on an earlier shutdown. This may be because Tomcat didn't shutdown cleanly and so session objects got corrupted during serialization.

One way to make this error go away would be to disable session persistence across restarts. You can do this by editing the file CATALINA_HOME/conf/context.xml and setting the pathname attribute of the <Manager> to an empty string. This is well documented in the file for Tomcat 7:

<!-- Uncomment this to disable session persistence across Tomcat restarts -->

<Manager pathname="" />

You should also delete any old session.ser files from the CATALINA_HOME/work/Catalina/localhost/<appName> folder whilst Tomcat is shutdown.

This may not be acceptable in your case if session persistence across restarts is needed. In which case further debugging of the issue would be necessary.

Will Keeling
  • 22,055
  • 4
  • 51
  • 61
39

Delete tomcat "work" folder. Restart tomcat server, hopefully now it'll run without any exception or error!

This can be done by selecting the server within Tomcat and selecting "Clean Tomcat Work Directory"

enter image description here

Jack
  • 2,891
  • 11
  • 48
  • 65
M.Nethaji
  • 399
  • 3
  • 3
12

If you are working with Spring Boot, just add it to the application.properties:

server.servlet.session.persistent=false
Pipiluço
  • 121
  • 1
  • 4
5

Just Clean the Tomcat Work Directory..which is worked well to me.

3

It is Simply just Because Persist Class was not Serialize Properly just Stop Apache. Remove Project and Clean Project and Server as well.

and Just Redeploy Here its Done. good luck.

Kishan Bheemajiyani
  • 3,429
  • 5
  • 34
  • 68
3

-The class should implement Serializable interface with serialVersionUID. - Do the clean build and restart the server

  • This is the real correct answer. The error happens when trying to deserialize a stream with a class that does not implement Serializable. The main problem is that the exception does not tell you which class that was written to the serialized stream is not Serializable and thus cannot be read back in. Therefore, finding the class that is not Serializable can be like finding a needle in a haystack. You have to methodically go through all of your classes that could be serialized in the session and make sure they are Serializable. – Pixelstix Mar 30 '23 at 15:36
1

I had a similar error with a project in eclipse. I solved it with these steps:

  • Make a clean to the project
  • Delete the Tomcat server at the server view of eclipse
  • Define a new Tomcat server at the server view of eclipse using the wizard
  • Add the project to the newly defined Tomcat server

After that, running this new Tomcat server all worked perfectly.

ugo
  • 2,705
  • 2
  • 30
  • 34
agugar
  • 19
  • 1
0

In Spring boot you @ResponseBody annotation on your @GetMapping endpoint.

Ramin Ar
  • 1,213
  • 13
  • 10