在多个模块中使用 Spring 缓存注解 [英] Using Spring cache annotation in multiple modules

查看:40
本文介绍了在多个模块中使用 Spring 缓存注解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 util 模块,可以生成一个用于其他应用程序的 jar.我希望这个模块使用缓存,并且更喜欢使用 Spring 的 annotation-driven 缓存.

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-Module 应该是这样的:

So Util-Module would have something like this:

DataManager.java

...
@Cacheable(cacheName="getDataCache")
public DataObject getData(String key) { ... }
...

data-manager-ehcache.xml

...
<cache name="getDataCache" maxElementsInMemory="100" eternal="true" />
...

data-manager-spring-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 注释进行缓存,同时将上述 jar 作为依赖项包含在内.所以我的 Deployable-Unit 应该是这样的:

MyApp.java

...
@Cacheable(cacheName="getMyAppObjectCache")
public MyAppObject getMyAppObject(String key) { ... }
...

my-app-ehcache.xml

...
<cache name="getMyAppObjectCache" maxElementsInMemory="100" eternal="true" />
...

my-app-spring-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?

如果不是,请解释为什么不是.如果是这样,将不胜感激对上述配置中需要更改的内容的解释.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆