1.spring配置

<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<context:component-scan base-package="com.spring.memcached"></context:component-scan>

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

<bean id="memcachedPool" class="com.danga.MemCached.SockIOPool" factory-method="getInstance"
init-method="initialize">
<constructor-arg>
<value>neeaMemcachedPool</value>
</constructor-arg>
<property name="servers">
<list>
<value>127.0.0.1:11211</value>
</list>
</property>
<property name="initConn">
<value>20</value>
</property>
<property name="minConn">
<value>10</value>
</property>
<property name="maxConn">
<value>50</value>
</property>
<property name="socketTO">
<value>3000</value>
</property>
</bean>

<bean id="memcachedClient" class="com.danga.MemCached.MemCachedClient">
<constructor-arg>
<value>neeaMemcachedPool</value>
</constructor-arg>
</bean>
</beans>

2测试

public class SpringMemcached {
@Autowired
private MemCachedClient mcc;

public static void main(String[] args) {
// TODO Auto-generated method stub

ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

SpringMemcached sct = (SpringMemcached) ctx.getBean("springMemcached");

sct.mcc.set("spring", "memcached");

Object obj = sct.mcc.get("spring");

System.out.println("obj:"+obj);
}

}

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄