spring中集成hazelcast

先將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了。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容