春天注解缓存:CacheDecoratorFactory没有配置defaultCache(Sprin

2019-10-16 22:01发布

我试图用自旋微观诠释缓存中的Ehcache。 所以,第一,我添加了依赖我的pom.xml和配置应用程序的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'

任何线索? 有些东西似乎是错我的配置。

谢谢你的时间
安德里亚

Answer 1:

安德烈,

确保与@Cachable注释bean的实例是管理的一个,而不是一个你正在创建自己的春天。 如果你有正确的方法被调用时,该日志会产生这样的事情:

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 annotation cache: CacheDecoratorFactory not configured for defaultCache