Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i cluster a spring mvc application?

I have a web application written with spring on a jetty server. because of load balancing i have to replicate http sessions and spring-security contexts over the web servers.

Can anybody point me at a working example how to make this possible?

the mvc controllers are part of spring-security-oauth2 so i have limited ability to influence them and jetty is a prerequisite for our environment. for most of the data and caching we will use infinispan.

I could not find any current information how tu cluster with spring, so i'm grateful for every help.

like image 727
Laures Avatar asked Oct 02 '12 19:10

Laures


1 Answers

  1. What is stateless, scales out automatically (like most of Spring beans and controllers)

  2. What is shared, must be replicated or all instances in the cluster must share on

    1. HTTP sessions must be replicated. If they are, Spring security (which stores security context in the session will just work

    2. Database will just work - you'll either just use one or replicate it as well

    3. Infinispan should handle replication of in-memory caches

Providing that you only store Serializable items in HTTP session and in caches, clustering your application should just work. Watch out for synchronized code (should locks be distributed?) and stateful beans.

See also

  • session not shared between two server
like image 120
Tomasz Nurkiewicz Avatar answered Nov 09 '22 08:11

Tomasz Nurkiewicz