第一步:在linux机或windows机上安装memcached服务端(server)
linux中安装memcached:centos中命令 yum -y install memcached
如果没有联网下载mencached的安装包(注意:需要安装依赖libevent)
从网上下载安装包,解压后make&&make install就完成了
第二步:项目中导入memcached客户端jar(client)有两个版本,选择2.4的
第三步:spring集成memcached(memcached.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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <!-- Memcached 配置 --> <bean id="memCachedClient" class="com.danga.MemCached.MemCachedClient"> <constructor-arg> <value>sockIOPool</value> </constructor-arg> </bean> <!-- Memcached连接池 --> <bean id="sockIOPool" class="com.danga.MemCached.SockIOPool" factory-method="getInstance" init-method="initialize" destroy-method="shutDown"> <constructor-arg> <value>sockIOPool</value> </constructor-arg> <property name="servers"> <list><!--memcached集群,有几个就列几个11211为端口号-->
<value>192.168.200.149:11211</value>
<value>192.168.200.150:11211</value>
</list>
</property> <property name="weights"> <list> <value>1</value> </list> </property> </bean></beans>