Spring注释缓存:未为defaultCache配置CacheDecoratorFactory

时间:2012-06-25 18:19:13

标签: java spring caching java-ee ehcache

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

<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配置文件:

<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添加到需要缓存的方法中:

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

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

似乎工作正常,但我收到了这条消息:

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'

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

感谢您的时间和安德里亚

1 个答案:

答案 0 :(得分:0)

安德烈,

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

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]