0

I have two different applications running on the same server. First application sets an object to an HttpSession. When I get this object from second application it throws ClassCastException.

The class is defined in a jar file and both the applications has access to the class I am setting in the HttpSession.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Please refer this: http://stackoverflow.com/questions/665941/any-way-to-share-session-state-between-different-applications-in-tomcat – Liu guanghua Dec 21 '15 at 06:41

1 Answers1

1

I assume the ClassCastException results from the situation that the class of the object beeing stored in the HttpSession is loaded from two different classloaders.

If your first application creates the object stored in the HttpSession then the object's class is loaded using classloader of the first application. If your second application tries to access the object from the HttpSession the second application also has to load the object's class. But the second application uses its own classloader which is a different classloader than the classloader of the first application.

The cast in the second application results in a ClassCastException because the class of the object stored in the HttpSession is loaded by another classloader than the class of the object of the cast's result.

You have to put the jar file with the class of the object stored in the HttpSession in a classloader that is the same for both applications. The way you can achive that depends on the application server you use. Check the documentation of your application server and especially how your application server organizes its class loaders.

Hope that helps

UliL
  • 21
  • 2