我一直在嘗試瞭解memcached的用法等,並試圖從昨天開始通過閱讀少量稀缺資源來設置它。首先讓我展示一下我擁有的東西。嘗試實例化xmemcached客戶端
- 安裝memcached服務器
配置爲彈簧所解釋here:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <import resource="simplesm-context.xml" /> <aop:aspectj-autoproxy /> <bean name="defaultMemcachedClient" class="com.google.code.ssm.CacheFactory"> <property name="cacheClientFactory"> <bean class="com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl" /> </property> <property name="addressProvider"> <bean class="com.google.code.ssm.config.DefaultAddressProvider"> <property name="address" value="127.0.0.1:11211" /> </bean> </property> <property name="configuration"> <bean class="com.google.code.ssm.providers.CacheConfiguration"> <property name="consistentHashing" value="true" /> </bean> </property> </bean> </beans>
成功創建與服務器的連接槽彈簧:
20:06:07,864 WARN [main] (XMemcachedClient.java:645) - XMemcachedClient use Text protocol 20:06:08,112 WARN [main] (AbstractController.java:372) - The Controller started at localhost/127.0.0.1:0 ... 20:06:08,139 WARN [Xmemcached-Reactor-0] (MemcachedConnector.java:239) - Add a session: 127.0.0.1:11211
所以下一步是對其進行測試,這提供了良好/簡單的解釋有關的memcached:http://www.majordojo.com/2007/03/memcached-howto.php
我想嘗試該位:
Class Foo {
public static findById(id) {
if (obj = memcached.get(id)) return obj;
obj = loadFromDatabase(id);
memcached.put(id,obj);
return obj;
}
}
但遠不在這個網站沒有說哪個對象的類型是memcached。於是,我試着用以下:
import net.rubyeye.xmemcached.MemcachedClient
Class Foo {
@Autowired
MemcachedClient defaultMemcachedClient;
public static findById(id) {
if (obj = memcached.get(id)) return obj;
obj = loadFromDatabase(id);
memcached.put(id,obj);
return obj;
}
}
錯誤我從日誌中得到的是:
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.rubyeye.xmemcached.MemcachedClient] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency
我想defaultMemcachedClient
豆應該是我的memcached客戶端。這並不明顯。我在這裏做什麼?任何人有想法?鏈接?建議嗎?什麼?