Spring注释缓存:未为defaultCache配置CacheDecoratorFactory [英] Spring annotation cache: CacheDecoratorFactory not configured for defaultCache

查看:272
本文介绍了Spring注释缓存:未为defaultCache配置CacheDecoratorFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用EhCache使用Sping Annotation缓存。因此,首先,我将依赖项添加到我的pom.xml并将application-context.xml配置为:

I'm trying to use Sping Annotation cache with EhCache. So, for first, I added the dependency to my pom.xml and configured the application-context.xml as:

<ehcache:annotation-driven cache-manager="cacheManager" />

<ehcache:config cache-manager="cacheManager">
    <ehcache:evict-expired-elements interval="60" />
</ehcache:config>

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation"  value="ehcache.xml"/>
</bean>

这是ehcache.xml配置文件:

This is the ehcache.xml configuration file:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />
    <cache name="alfresco" maxElementsInMemory="10" eternal="true" overflowToDisk="false" />
</ehcache>

最后,我将Annontation @Cachable添加到需要缓存的方法中:

for last, I added the Annontation @Cachable to the methods that need to be cached:

@Cacheable(value="alfresco")
public EMContents getContents(RestTemplate restTemplate, String ticket, String webScriptUrl, String em_name)

我创建一个junit类来调用两次相同的方法,并且它不使用第二次缓存(第一次没有创建键值)。

I create a junit class to call two times the same method, and, it doesn't use the cache the second time (the first one doesn't create the key value).

它似乎工作正常,但我收到此消息:

It seems to work fine, but I get this message:

25 Jun 2012 19:40:07  INFO EhCacheManagerFactoryBean:100 - Initializing EHCache CacheManager
25 Jun 2012 19:40:07 DEBUG ConfigurationFactory:148 - Configuring ehcache from InputStream
25 Jun 2012 19:40:07 DEBUG BeanHandler:271 - Ignoring ehcache attribute xmlns:xsi
25 Jun 2012 19:40:07 DEBUG BeanHandler:271 - Ignoring ehcache attribute xsi:noNamespaceSchemaLocation
25 Jun 2012 19:40:07 DEBUG PropertyUtil:88 - propertiesString is null.
25 Jun 2012 19:40:07 DEBUG CacheManager:605 - No disk store path defined. Skipping disk store path conflict test.
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:184 - No CacheManagerEventListenerFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:949 - No BootstrapCacheLoaderFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:923 - CacheWriter factory not configured. Skipping...
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:96 - No CacheExceptionHandlerFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:949 - No BootstrapCacheLoaderFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:923 - CacheWriter factory not configured. Skipping...
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:96 - No CacheExceptionHandlerFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:949 - No BootstrapCacheLoaderFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:923 - CacheWriter factory not configured. Skipping...
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:96 - No CacheExceptionHandlerFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:949 - No BootstrapCacheLoaderFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:923 - CacheWriter factory not configured. Skipping...
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:96 - No CacheExceptionHandlerFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:949 - No BootstrapCacheLoaderFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:923 - CacheWriter factory not configured. Skipping...
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:96 - No CacheExceptionHandlerFactory class specified. Skipping...
25 Jun 2012 19:40:07 DEBUG Cache:1183 - Initialised cache: alfresco_action
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:331 - CacheDecoratorFactory not configured. Skipping for 'alfresco_action'.
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:360 - CacheDecoratorFactory not configured for defaultCache. Skipping for 'alfresco_action'.
25 Jun 2012 19:40:07 DEBUG Cache:1183 - Initialised cache: alfresco
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:331 - CacheDecoratorFactory not configured. Skipping for 'alfresco'.
25 Jun 2012 19:40:07 DEBUG ConfigurationHelper:360 - CacheDecoratorFactory not configured for defaultCache. Skipping for 'alfresco'.
25 Jun 2012 19:40:07 DEBUG DefaultListableBeanFactory:458 - Finished creating instance of bean 'cacheManager'

有任何线索吗?我的配置似乎有些问题。

Any clue? Something seems to be wrong with my configuration.

感谢您的时间
Andrea

Thanks for your time
Andrea

推荐答案

Andrea ,

确保带有@Cachable注释的bean实例是Spring管理的实例,而不是您自己创建的实例。如果您有正确的日志,则在调用该方法时,日志将生成类似的内容:

Make sure that the instance of the bean with the @Cachable annotation is the spring managed one, not one you are creating yourself. If you have the right one the log will produce something like this when the method is invoked:

2012-11-16 09:40:21,731 [http-8081-2] DEBUG com.googlecode.ehcache.annotations.interceptor.EhCacheInterceptor  - Generated key '1396312488991822982' for invocation: ReflectiveMethodInvocation: public edu.wmich.gowmu.sso.dataobject.User edu.wmich.gowmu.sso.bl.UserManager.getUser(java.lang.String,java.lang.String); target is of class [edu.wmich.gowmu.sso.bl.UserManager]

这篇关于Spring注释缓存:未为defaultCache配置CacheDecoratorFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆