tomcat deploy war without losing session
Asked Answered
M

2

8

I am working on java web application deployment. I have requirement like we will be keep on deploying new versions of war file in tomcat app. My requirement is when a user is logged in and when I deploy a new war in tomcat web app it overrides old war and I loose session.

I should show user new version without loosing his session.

When I googled I came to know about tomcat parallel deployment. But my manager is asking no to follow that solution and asking to see any other solution is available. But I did not get any other solution.

Is there any way in tomcat to store sessions?

How about other servers like jboss, weblogic or websphere?

Maraca answered 14/1, 2015 at 8:31 Comment(4)
Not sure, but maybe you could serialize the session on shutdown and load it again on startup? I think maybe apache wicket and spring mvc supports that. But it would require your session objects to be serializableGaribald
Search for persistent sessions.Differentiation
This might help you - Persistence_Across_Restarts. And as you noticed full Java EE servers support that, usually via persistent sessions, for example WebSphere.Bathrobe
Another Idea, store the session and use a listener to detect when the war is deployed/undeployed example hereNinfaningal
F
11

As mentioned by Gas, see http://tomcat.apache.org/tomcat-7.0-doc/config/manager.html#Persistence_Across_Restarts

Configure <Manager> with some explicit path name. By default the sessions are stored in the work directory of a web application. The work directory is deleted when a web application is undeployed.

If you configure the pathname attribute explicitly to point to some directory that is not deleted on undeployment, the sessions will survive.

Note that you can use ${catalina.base} and other system properties in your configuration.

Frydman answered 18/1, 2015 at 11:23 Comment(0)
R
2

Are you familiar with Redis? It is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.

Using the Redisson java client, you can configure the RedissonSessionManager, which persists all of Tomcat’s session data in Redis.

This way, if you restart your Tomcat instance it will recover the session from Redis once it is started.

This approach has the additional advantage, of being a very convenient way to share your session data between different Tomcat instances, allowing you to cluster them behind a Load Balancer without session stickiness (like nginx).

You can read more about configuring tomcat with the RedissonSessionManager here:

https://dzone.com/articles/redis-based-tomcat-session-management

Good luck!

Rafaelarafaelia answered 21/3, 2020 at 7:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.