這篇文章主要介紹了spring與memcached如何集成,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
創(chuàng)新互聯(lián)科技有限公司專業(yè)互聯(lián)網(wǎng)基礎(chǔ)服務(wù)商,為您提供成都天府聯(lián)通服務(wù)器托管,高防主機(jī),成都IDC機(jī)房托管,成都主機(jī)托管等互聯(lián)網(wǎng)服務(wù)。
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:hcj="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd "> <!-- 通過單例模式factory-method去找到無參的構(gòu)造,構(gòu)造方法調(diào)用的還是SchoonerSockIOPool.getInstance方法,然后再進(jìn)行的初始化 --> <bean id="sockIOPool" class="com.danga.MemCached.SockIOPool" factory-method="getInstance" init-method="initialize"> <property name="servers"> <list> <value>ip和端口號</value> </list> </property> </bean> </beans>
java class
package com.bw.memcached; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.danga.MemCached.MemCachedClient; import com.danga.MemCached.SockIOPool; //import com.schooner.MemCached.SchoonerSockIOPool; public class MemcachedTest { public static void main(String[] args) { @SuppressWarnings("resource") ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); context.getBean("sockIOPool",SockIOPool.class); MemCachedClient client = new MemCachedClient(); // SockIOPool sockIo = SockIOPool.getInstance(); //得到一個初始的池子用來存放連接 // String[] as = {"ip:端口號"}; //聲明一個字符串?dāng)?shù)組,存放連接 // sockIo.setServers(as); //將所有的連接加入池子 // sockIo.setInitConn(10); //設(shè)置初始化連接數(shù) // sockIo.initialize(); //進(jìn)行初始化 // System.out.println("=======初始化連接數(shù)======="+sockIo.getInitConn()); client.add("鍵", "對象"); System.out.println(client.get("鍵")); //以上注釋的都是在沒有與spring集成的情況下 } }
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“spring與memcached如何集成”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!
網(wǎng)站欄目:spring與memcached如何集成
文章轉(zhuǎn)載:http://sd-ha.com/article26/ggsscg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、軟件開發(fā)、App開發(fā)、網(wǎng)站設(shè)計(jì)公司、建站公司、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)