先将hazelcast-all-x.x.x.jar放到项目的lib中,
将hazelcast.xml复制到项目的根目录中。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="instance" class="com.hazelcast.core.Hazelcast" factory-method="newHazelcastInstance"></bean>
<bean name="multiMap" factory-bean="instance" factory-method="getMultiMap">
<constructor-arg value="userSession"/>
</bean>
</beans>
<constructor-arg value="userSession"/>的userSession名字随便取。
在hazelcast的管理界面会显示的。
id="instance"的bean不写<constructor-arg>会在根目录中寻找hazelcast.xml文件的。
除了有getMultiMap外,还有getMap,getQueue,getTopic,getSet,getList,getExecutorService,getIdGenerator,getAtomicLong,getSemaphore,getCountDownLatch,getLock等。
@Autowired
private MultiMap<String, Object> multiMap;
在java代码中这样就可以操作MultiMap了。