首页 > 代码库 > Spring集成spymemcached
Spring集成spymemcached
Spring集成spymemcached
Memcached的安装部署我就不介绍了!
首先下载spymemcached,下载地址:
jar:https://spymemcached.googlecode.com/files/spymemcached-2.10.3.jar
javadoc:https://spymemcached.googlecode.com/files/spymemcached-2.10.3-javadoc.jar
源码:https://spymemcached.googlecode.com/files/spymemcached-2.10.3-sources.jar
Spring的配置文件:config-cache.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" 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.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="memcachedClient" class="net.spy.memcached.spring.MemcachedClientFactoryBean"> <property name="servers" value="http://www.mamicode.com/#{configproperties[‘memcached.server.url‘]}" /> <property name="protocol" value="http://www.mamicode.com/BINARY" /> <property name="transcoder"> <bean class="net.spy.memcached.transcoders.SerializingTranscoder"> <property name="compressionThreshold" value="http://www.mamicode.com/1024" /> </bean> </property> <property name="opTimeout" value="http://www.mamicode.com/1000" /> <property name="timeoutExceptionThreshold" value="http://www.mamicode.com/2000" /> <!-- 这是一个坑:<property name="hashAlg" value="http://www.mamicode.com/KETAMA_HASH"/>--> <property name="hashAlg"> <value type="net.spy.memcached.DefaultHashAlgorithm">KETAMA_HASH</value> </property> <property name="locatorType" value="http://www.mamicode.com/CONSISTENT" /> <property name="failureMode" value="http://www.mamicode.com/Redistribute" /> <property name="useNagleAlgorithm" value="http://www.mamicode.com/false" /> </bean> </beans>
Spring的配置文件:config-service.xml
<bean class="com.digitalchina.security.interceptor.ToKenCheckInterceptor" > <property name="memcachedClient" ref="memcachedClient" /> </bean>
Spring的源码:
@Component public class ToKenCheckInterceptor extends AbstractWebServiceInterceptor implements InitializingBean { public static final String CSP_USER_SECURITY_CONTEXT_KEY = "CSP_USER_SECURITY_CONTEXT_KEY"; public static final int HTTP_STATUS_INSUFFICIENT_USER_LEVEL = 431; @Autowired private MemcachedClient memcachedClient; public void setMemcachedClient(MemcachedClient memcachedClient) { this.memcachedClient = memcachedClient; } 。。。 。。。
本文出自 “梦朝思夕” 博客,请务必保留此出处http://qiangmzsx.blog.51cto.com/2052549/1413649
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。