gpt4 book ai didi

java - 基于 Spring 的单个 ehcache 管理器,用于多模块项目中的多个 ehcache.xml 文件

转载 作者:太空宇宙 更新时间:2023-11-04 12:05:03 25 4
gpt4 key购买 nike

我有一个多模块项目,所有模块都在自己的 ehcache.xml 中定义其缓存配置。现在未维护的“ehcache-spring-annotations”项目通过如下配置解决了此用例:

    <ehcache:annotation-driven cache-manager="ehCacheManager" create-missing-caches="true"/>

<bean id="ehCacheManager" class="net.sf.itcb.addons.cachemanager.ItcbEhCacheManagerFactoryBean">
<property name="configLocations" value="classpath*:ehcache.xml"/>
<property name="shared" value="true"/>
</bean>

我在 Spring 的缓存抽象中尝试了类似的方法。

    <cache:annotation-driven/>

<bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheCacheManager"
p:cache-manager-ref="ehcache"/>

<bean id="ehcache"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:config-location="classpath*:ehcache.xml"/>

但是,我遇到了这个异常:

Caused by: java.io.FileNotFoundException: 
class path resource [classpath*:ehcache.xml] cannot be opened because
it does not exist

有人可以解释一下在多模块项目中为 EhCache 配置 Spring 缓存抽象的正确方法是什么吗?

最佳答案

如果您希望在单个 Spring 上下文中使用多个 CacheManager,则必须定义多个 bean 并向它们添加限定符,以便能够根据某些上下文区分它们。

所以这里没有什么具体的缓存,它是 Spring 中相同类型的经典多个 bean。

关于java - 基于 Spring 的单个 ehcache 管理器,用于多模块项目中的多个 ehcache.xml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40460488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com