java Spring注解缓存:没有为默认缓存配置CacheDecoratorFactory

3lxsmp7m  于 2022-10-30  发布在  Java
关注(0)|答案(1)|浏览(330)

我尝试将Sping Annotation缓存与EhCache一起使用。因此,首先,我将依赖项添加到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'

有什么线索吗?我的配置似乎有问题。
感谢您抽出宝贵时间
安德里亚

rnmwe5a2

rnmwe5a21#

安德莉亚,
确保带有@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]

相关问题