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>

<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>地址:端口号</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);
}

}

 

posted on 2019-05-07 20:31  许天天  阅读(245)  评论(0)    收藏  举报