memcache与spring集成
2017-01-13 16:05
573 查看
一、前期准备
用的是junit4
1) 下载memcached服务端memcached-1.2.6-win32-bin.zip,地址:http:
//code.jellycan.com/memcached/
<?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" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:properties/memcache.properties</value> </list> </property> </bean> <bean id="memcachedPool" class="com.danga.MemCached.SockIOPool" factory-method="getInstance" init-method="initialize" destroy-method="shutDown"> <constructor-arg> <value>memCachedPool</value> </constructor-arg> <property name="servers"> <list> <value>${memcache.server}</value> </list> </property> <property name="initConn"> <value>${memcache.initConn}</value> </property> <property name="minConn"> <value>${memcache.minConn}</value> </property> <property name="maxConn"> <value>${memcache.maxConn}</value> </property> <property name="maintSleep"> <value>${memcache.maintSleep}</value> </property> <property name="nagle"> <value>${memcache.nagle}</value> </property> <property name="socketTO"> <value>${memcache.socketTO}</value> </property> </bean> <bean id="memCachedClient" class="com.danga.MemCached.MemCachedClient"> <constructor-arg> <value>memCachedPool</value> </constructor-arg> </bean> </beans>memcache.properties memcache的连接属性 这是本机做服务器的,如果是其它机器,换ip 端口即可
memcache.server=127.0.0.1:11211 memcache.initConn=20 memcache.minConn=10 memcache.maxConn=50 memcache.maintSleep=3000 memcache.nagle=false memcache.socketTO=3000TestMemcache.Java测试类
用的是junit4
package com.pis.memcache; import org.junit.Before; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.danga.MemCached.MemCachedClient; public class TestMemcache { MemCachedClient memCachedClient; @Before public void beforeTest(){ ApplicationContext atx = new ClassPathXmlApplicationContext("/spring/spring-memcache.xml"); memCachedClient = (MemCachedClient)atx.getBean("memCachedClient"); } @Test public void TestMem(){ memCachedClient.set("name", "han"); System.out.println(memCachedClient.get("name")); } }
相关文章推荐
- Memcache与Spring集成实例
- spring集成memcache 示例二
- memcache与spring集成 实例
- spring缓存集成memcache
- Memcache集成spring
- memcache与spring集成 实例
- spring与memcache的集成
- spring与memcache的集成
- spring集成memcache 示例一
- spring与memcache的集成
- spring缓存集成memcache
- spring集成memcache 示例二
- Spring 集成 MemCache
- memcache与spring集成 实例
- Memcache Spring集成
- 搭建JAVAEE Memcache 集群环境之与Spring集成(四)
- spring缓存集成memcache
- Spring集成Memcache实例
- java(样品集成框架spring、spring mvc、spring data jpa、hibernate)
- Spring集成Spring-data-redis RedisCacheManager缓存源码分析