我正在使用 memcached 根据他们在地址中所说的操作:https ://code.google.com/p/simple-spring-memcached/wiki/Getting_Started 。完成它的服务器上的内存缓存,我已经安装了。该库应该需要您的项目。但是运行时会出现输出。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultCache' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.google.code.ssm.CacheFactory]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jackson/Versioned
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBea n(AbstractAutowireCapableBeanFactory.java:965)
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.google.code.ssm.CacheFactory]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jackson/Versioned
我对这样的方法使用缓存
@ReadThroughSingleCache(namespace = "CplxObj", expiration = 0)
public List<Answer> showAnswer(int id){
并在 dispatcher-servlet.xml 添加这个
<cache:annotation-driven />
<bean name="cacheManager" class="com.google.code.ssm.spring.SSMCacheManager">
<property name="caches">
<set>
<bean class="com.google.code.ssm.spring.SSMCache">
<constructor-arg name="cache" index="0" ref="defaultCache" />
<!-- 5 minutes -->
<constructor-arg name="expiration" index="1" value="300" />
<!-- @CacheEvict(..., "allEntries" = true) won't work because allowClear is false,
so we won't flush accidentally all entries from memcached instance -->
<constructor-arg name="allowClear" index="2" value="false" />
</bean>
</set>
</property>
<bean name="defaultCache" class="com.google.code.ssm.CacheFactory">
<property name="cacheName" value="defaultCache" />
<property name="cacheClientFactory">
<bean name="cacheClientFactory" class="com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl" />
</property>
<property name="addressProvider">
<bean class="com.google.code.ssm.config.DefaultAddressProvider">
<property name="address" value="199.26.84.24:11211" />
</bean>
</property>
<property name="configuration">
<bean class="com.google.code.ssm.providers.CacheConfiguration">
<property name="consistentHashing" value="true" />
</bean>
</property>
</bean>
为什么这是个问题 ?
************************* 更改后出现此错误 ******************** **********
Error creating bean with name 'cacheManager' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot create inner bean 'com.google.code.ssm.spring.SSMCache#b53b32' of type [com.google.code.ssm.spring.SSMCache] while setting bean property 'caches' with key [0];
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.google.code.ssm.spring.SSMCache#b53b32' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'defaultCache' while setting constructor argument;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultCache' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot create inner bean 'cacheClientFactory' of type [com.google.code.ssm.providers.spymemcached.MemcacheClientFactoryImpl] while setting bean property 'cacheClientFactory';
nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.google.code.ssm.providers.spymemcached.MemcacheClientFactoryImpl] for bean with name 'cacheClientFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml];
nested exception is java.lang.ClassNotFoundException: com.google.code.ssm.providers.spymemcached.MemcacheClientFactoryImpl
Error creating bean with name 'com.google.code.ssm.spring.SSMCache#b53b32' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'defaultCache' while setting constructor argument;