Any way to share session state between different applications in tomcat? Any way to share session state between different applications in tomcat? java java

Any way to share session state between different applications in tomcat?


You should not share HttpSession; but you can share other objects. For example, you can register an object via JNDI and access the same object in all your apps (databases use this to pool connections).


One thing to be aware of is that two web apps will use different classloaders. If you want to share objects, they need to use the same version of the class from the same classloader (or else you will get LinkageErrors). That means either putting them in a classloader shared by both web apps (system classpath for example) OR using serialization to effectively drain and reconstitute the object in the right classloader with the correct version of the class.


If you want to use Spring, there's a project called Spring Session:https://github.com/spring-projects/spring-session

Quoting: "HttpSession - allows replacing the HttpSession in an application container (i.e. Tomcat) neutral way"