How do you use Hazelcast as a http session store with embedded Tomcat with Spring Boot and Spring Security? I see there is a EmbeddedServletContainerCustomizer and SpringAwareWebFilter but I don't understand how to use it.
Spring Boot with Hazelcast and Tomcat
6.7k Views Asked by gx0r At
2
There are 2 best solutions below
0

Why not uses Spring-session? It is pretty easy.
Instead of using Tomcat’s HttpSession, we are actually persisting the values in Redis. Spring Session replaces the HttpSession with an implementation that is backed by Redis. When Spring Security’s SecurityContextPersistenceFilter saves the SecurityContext to the HttpSession it is then persisted into Redis.
@EnableRedisHttpSession
public class HttpSessionConfig {
}
#src/main/resources/application.properties
spring.redis.host=localhost
spring.redis.password=secret
spring.redis.port=6379
http://docs.spring.io/spring-session/docs/current/reference/html5/guides/boot.html
As described in Hazelcast's documentation, you need to configure Hazelcast's
SpringAwareWebFilter
andSessionListener
. You can do so in Spring Boot by declaring aFilterRegistrationBean
and aServletListenerRegistrationBean
respectively:SpringAwareWebFilter
andSessionListener
are both in Hazelcast'shazelcast-wm
module so you'll need to add a dependency oncom.hazelcast:hazelcast-wm
to yourpom.xml
orbuild.gradle
.hazelcast-wm
also requires Spring Security to be on the classpath.Now, when you run your application, you should see log output from Hazelcast during startup that's similar to the following: