views:

107

answers:

1

Building a JSF application with Spring on Tomcat. The target is a web farm, and the client has requested that we design our application so that it can be load balanced without relying on "sticky sessions" in the LB.

In .NET, you can configure the session store to be SQL Server or the ASP.NET State Service. What alternatives are there in the Java world? Is there a standard way to plug in a different session state store that points to a MySQL database for example? Does Spring provide any hooks?

+1  A: 

This is servletcontainer specific which in this case is Tomcat. The servletcontainer is the one which manages and provides the sessions. So JSF and Spring have nothing to do here. They just transparently gets it from the servletcontainer by request.getSession() and so on.

In Tomcat, you can provide a custom session manager implementation in the webapp's Context:

<Context ...>
    <Manager className="com.example.SessionManager">

..where com.example.SessionManager implements org.apache.catalina.Manager as per its contract. Therein you can write code to back the sessions by a database.

However, there are alternatives for your particular requirement, you can choose for Tomcat's builtin clustering/session-replication capabilities instead of reinventing it with a custommade manager/database. Read more about it at the Tomcat Clustering/Session Replication HOW-TO.

BalusC
As it turns out we're only using tomcat in development, the production site is using websphere, which has its own implementation (http://publib.boulder.ibm.com/infocenter/wasinfo/v4r0/index.jsp?topic=/com.ibm.websphere.v4.doc/wass_content/06061105.html). But knowing this is container-specific is enough to make recommendations for deployment. Thanks!
roufamatic
You're welcome. It might be useful to know that Websphere actually uses Tomcat "under the hoods".
BalusC