Search code examples
spring-session

Does spring-session support saving the session when "setAttribute" is called on the session?


It appears the primary behavior of Spring session is to save the session when the HttpResponse is committed.

Does spring-session also support saving the session when "setAttribute" is called on the session ?


Solution

  • If you're using Spring Session with either Redis or Hazelcast session stores, you can set the flush mode to IMMEDIATE (ON_SAVE is the default). This will result in changes to session being persistent to underlying store immediately as they are made.

    Take a look at @EnableRedisHttpSession or @EnableHazelcastHttpSession annotations.