如Hazelcast的文档中所述,您需要配置Hazelcast的
SpringAwareWebFilter和
SessionListener。您可以在Spring
Boot中通过分别声明a
FilterRegistrationBean和a
来做到这
ServletListenerRegistrationBean一点:
@Beanpublic FilterRegistrationBean hazelcastFilter() { FilterRegistrationBean registration = new FilterRegistrationBean(new SpringAwareWebFilter()); registration.addUrlPatterns("/*"); registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE); // Configure init parameters as appropriate: // registration.addInitParameter("foo", "bar"); return registration;}@Beanpublic ServletListenerRegistrationBean<SessionListener> hazelcastSessionListener() { return new ServletListenerRegistrationBean<SessionListener>(new SessionListener());}SpringAwareWebFilter并且
SessionListener都在Hazelcast的
hazelcast-wm模块,所以你需要在添加一个依赖
com.hazelcast:hazelcast-wm于你
pom.xml或
build.gradle。
hazelcast-wm还需要Spring Security放在类路径上。
现在,当您运行应用程序时,应该在启动过程中看到Hazelcast的日志输出,类似于以下内容:
2014-12-17 10:29:32.401 INFO 94332 --- [ost-startStop-1] com.hazelcast.config.XmlConfigLocator : Loading 'hazelcast-default.xml' from classpath.2014-12-17 10:29:32.435 INFO 94332 --- [ost-startStop-1] c.hazelcast.web.HazelcastInstanceLoader : Creating a new HazelcastInstance for session replication2014-12-17 10:29:32.582 INFO 94332 --- [ost-startStop-1] c.h.instance.DefaultAddressPicker : [LOCAL] [dev] [3.3.3] Prefer IPv4 stack is true.2014-12-17 10:29:32.590 INFO 94332 --- [ost-startStop-1] c.h.instance.DefaultAddressPicker : [LOCAL] [dev] [3.3.3] Picked Address[169.254.144.237]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true2014-12-17 10:29:32.612 INFO 94332 --- [ost-startStop-1] c.h.spi.impl.BasicOperationScheduler : [169.254.144.237]:5701 [dev] [3.3.3] Starting with 16 generic operation threads and 16 partition operation threads.2014-12-17 10:29:32.657 INFO 94332 --- [ost-startStop-1] com.hazelcast.system : [169.254.144.237]:5701 [dev] [3.3.3] Hazelcast 3.3.3 (20141112 - eadb69c) starting at Address[169.254.144.237]:57012014-12-17 10:29:32.657 INFO 94332 --- [ost-startStop-1] com.hazelcast.system : [169.254.144.237]:5701 [dev] [3.3.3] Copyright (C) 2008-2014 Hazelcast.com2014-12-17 10:29:32.661 INFO 94332 --- [ost-startStop-1] com.hazelcast.instance.Node : [169.254.144.237]:5701 [dev] [3.3.3] Creating MulticastJoiner2014-12-17 10:29:32.664 INFO 94332 --- [ost-startStop-1] com.hazelcast.core.LifecycleService : [169.254.144.237]:5701 [dev] [3.3.3] Address[169.254.144.237]:5701 is STARTING2014-12-17 10:29:38.482 INFO 94332 --- [ost-startStop-1] com.hazelcast.cluster.MulticastJoiner : [169.254.144.237]:5701 [dev] [3.3.3]Members [1] { Member [169.254.144.237]:5701 this}2014-12-17 10:29:38.503 INFO 94332 --- [ost-startStop-1] com.hazelcast.core.LifecycleService : [169.254.144.237]:5701 [dev] [3.3.3] Address[169.254.144.237]:5701 is STARTED


