我一直在尝试了解 memcached 的使用等,并尝试从昨天开始通过阅读一些稀缺资源来进行设置。让我从展示我拥有的东西开始。
- 安装的 memcached 服务器
为弹簧配置,如下所述:
<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>
通过 spring 成功创建到服务器的连接:
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;
}
}
但是该站点上没有任何地方说明内存缓存的对象类型。所以我尝试了以下方法:
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
bean 应该是我的 memcached 客户端。这并不明显。我在这里做什么?有人有想法吗?关联?建议?任何事物?