evg02gsa3
evg02gsa3

Reputation: 591

Servlet, Spring: share session across multiple servers

Let's say I have a Java Servlet+JSP app using Spring framework and Tomcat 6. This app must be hosted on multiple machines. How can I share the HTTP session across many computers?

I usually get my session using this code:

HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpSession session = httpRequest.getSession();

Should I use some other kind of session (custom implementation of HttpSession) using a common MySQL db or something? Any idea?

Upvotes: 1

Views: 1500

Answers (1)

zmitrok
zmitrok

Reputation: 388

If you want to use a shared HTTP session storage you need to override the session manager in the application server that you use. Here is a link for Tomcat 8 to give you an idea - http://tomcat.apache.org/tomcat-8.0-doc/config/manager.html

To answer the 'should' part of your question - you don't have to. You could use session cookie based 'stickiness' option on your load balancer as an alternative to shared cookie storage.

Upvotes: 1

Related Questions