我正在尝试使用Spring Modules项目中的声明性缓存。
它不起作用。似乎没有任何东西被缓存。
这是我的配置:
<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
</bean>
<bean id="cacheProviderFacade"
class="org.springmodules.cache.provider.ehcache.EhCacheFacade">
<property name="cacheManager" ref="cacheManager" />
</bean>
<bean id="cacheableService"
class="org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean">
<property name="cacheProviderFacade" ref="cacheProviderFacade" />
<property name="cachingModels">
<props>
<prop key="get*">cacheName=default</prop>
</props>
</property>
<property name="flushingModels">
<props>
<prop key="update*">cacheNames=default</prop>
</props>
</property>
<property name="target" ref="myServiceBean" />
</bean>
然后,这是从Spring加载应用程序上下文时的日志记录......
24 Feb 2009 14:26:20,785 INFO org.springframework.cache.ehcache.EhCacheManagerFactoryBean - Initializing EHCache CacheManager
24 Feb 2009 14:26:20,801 DEBUG net.sf.ehcache.CacheManager - Configuring ehcache from classpath.
24 Feb 2009 14:26:20,801 WARN net.sf.ehcache.config.ConfigurationFactory - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: zip:C:/bea/weblogic81/server/bin/myserver/.wlnotdelete/extract/myserver_threeoneoneonline_threeoneoneonline/jarfiles/WEB-INF/lib/ehcache-1.3.0.jar!/ehcache-failsafe.xml
24 Feb 2009 14:26:20,801 DEBUG net.sf.ehcache.config.ConfigurationFactory - Configuring ehcache from URL: zip:C:/bea/weblogic81/server/bin/myserver/.wlnotdelete/extract/myserver_threeoneoneonline_threeoneoneonline/jarfiles/WEB-INF/lib/ehcache-1.3.0.jar!/ehcache-failsafe.xml
24 Feb 2009 14:26:20,801 DEBUG net.sf.ehcache.config.ConfigurationFactory - Configuring ehcache from InputStream
24 Feb 2009 14:26:20,816 DEBUG net.sf.ehcache.config.DiskStoreConfiguration - Disk Store Path: C:\DOCUME~1\bpapa\LOCALS~1\Temp\
24 Feb 2009 14:26:20,832 DEBUG net.sf.ehcache.config.ConfigurationHelper - No CacheManagerEventListenerFactory class specified. Skipping...
24 Feb 2009 14:26:20,832 DEBUG net.sf.ehcache.config.ConfigurationHelper - No CachePeerListenerFactoryConfiguration specified. Not configuring a CacheManagerPeerListener.
24 Feb 2009 14:26:20,847 DEBUG net.sf.ehcache.config.ConfigurationHelper - No CachePeerProviderFactoryConfiguration specified. Not configuring a CacheManagerPeerProvider.
24 Feb 2009 14:26:20,863 DEBUG net.sf.ehcache.config.ConfigurationHelper - No BootstrapCacheLoaderFactory class specified. Skipping...
在此之后,我点击了一个页面,该页面调用了来自“myServiceBean”bean的前缀为“get”的方法。但是,没有记录任何缓存正在进行。我已经将日志记录一直调试为springmodules,spring的缓存包和DEBUG ...因为Spring Modules的例子很少,而且在网络上很远,我想知道是否有人之前看过这个... < / p>
答案 0 :(得分:2)
您应该为您的配置创建一个ehcache.xml文件,因为我不相信故障安全缓存与声明性缓存一起使用。我们使用ehcache Spring模块XML模式和注释来设置缓存。如果使用显式的ehcache.xml无法解决您的问题,那么我可以挖掘出一些代码(接近)。
答案 1 :(得分:1)
我是一个新项目的作者之一,该项目旨在通过注释为Spring 3项目提供Ehcache集成:
http://code.google.com/p/ehcache-spring-annotations/
该库以Spring的@Transactional精神提供了两个方法级注释:
@Cacheable @TriggersRemove
在Spring应用程序中进行适当配置后,该项目将在运行时围绕@Cacheable带注释的方法创建缓存方面。
可以在项目维基上找到使用文档