在多个模块使用Spring缓存注解 [英] Using Spring cache annotation in multiple modules
问题描述
我在其他应用程序中使用产生一个罐子一个实用程序模块。我想这个模块使用缓存,并将preFER使用Spring的注释驱动
缓存。
I have a util module that produces a jar to be used in other applications. I'd like this module to use caching and would prefer to use Spring's annotation-driven
caching.
所以的Util-模块
将有这样的事情:
DataManager.java
...
@Cacheable(cacheName="getDataCache")
public DataObject getData(String key) { ... }
...
数据管理器 - ehcache.xml中
...
<cache name="getDataCache" maxElementsInMemory="100" eternal="true" />
...
数据管理器弹簧-config.xml中
...
<cache:annotation-driven cache-manager="data-manager-cacheManager" />
<!-- ???? --->
<bean id="data-manager-cacheManager"
class="org.springframework.cache.ehcache.EhcacheCacheManager"
p:cache-manager="data-manager-ehcache"/>
<bean id="data-manager-ehcache"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:config-location="data-manager-ehcache.xml"/>
...
我也想我的部署单元有通过Spring注解缓存,同时包括上述罐子作为一个依赖。所以,我的部署单位
将有这样的事情:
MyApp.java
...
@Cacheable(cacheName="getMyAppObjectCache")
public MyAppObject getMyAppObject(String key) { ... }
...
我的应用 - ehcache.xml中
...
<cache name="getMyAppObjectCache" maxElementsInMemory="100" eternal="true" />
...
我的应用弹簧-config.xml中
...
<cache:annotation-driven cache-manager="my-app-cacheManager" />
<!-- ???? --->
<bean id="my-app-cacheManager"
class="org.springframework.cache.ehcache.EhcacheCacheManager"
p:cache-manager="my-app-ehcache"/>
<bean id="my-app-ehcache"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:config-location="my-app-ehcache.xml"/>
...
问:
时有可能使用注解驱动的缓存在两个主项目和一个依赖模块,同时保持配置分开吗?
Question:
Is it possible to use annotation driven caching in both your main project and a dependency module while keeping the configurations separated?
如果不是,为什么它没有将AP preciated的解释。如果是这样,什么需要解释在上面的配置更改将AP preciated。
If not, an explanation of why it isn't would be appreciated. If so, an explanation of what needs to change in the above configuration would be appreciated.
推荐答案
这似乎是固定在3.2M1,请参阅https://jira.springsource.org/browse/SPR-8696
this seems to be fixed in 3.2M1, see https://jira.springsource.org/browse/SPR-8696
这篇关于在多个模块使用Spring缓存注解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!