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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<? 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 = "#{configproperties['memcached.server.url']}" />
< property name = "protocol" value = "BINARY" />
< property name = "transcoder" >
< bean class = "net.spy.memcached.transcoders.SerializingTranscoder" >
< property name = "compressionThreshold" value = "1024" />
</ bean >
</ property >
< property name = "opTimeout" value = "1000" />
< property name = "timeoutExceptionThreshold" value = "2000" />
<!-- 这是一个坑:<property name="hashAlg" value="KETAMA_HASH"/>-->
< property name = "hashAlg" >
< value type = "net.spy.memcached.DefaultHashAlgorithm" >KETAMA_HASH</ value >
</ property >
< property name = "locatorType" value = "CONSISTENT" />
< property name = "failureMode" value = "Redistribute" />
< property name = "useNagleAlgorithm" value = "false" />
</ bean >
</ beans >
|
Spring的配置文件:config-service.xml
1
2
3
|
< bean class = "com.digitalchina.security.interceptor.ToKenCheckInterceptor" >
< property name = "memcachedClient" ref = "memcachedClient" />
</ bean >
|
Spring的源码:
1
2
3
4
5
6
7
8
9
10
11
12
|
@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;
}
。。。 。。。
|
本文转自 梦朝思夕 51CTO博客,原文链接:
http://blog.51cto.com/qiangmzsx/1413649