是否可以使用多个ehcache.xml(在不同的项目中,同样的战争)?

Iva*_*vov 18 java ehcache war configuration-files web-deployment

我有一个服务项目和一个Web项目.我需要在两个项目中都有eh-cache.

这个想法是,如果服务项目更新,它的缓存相关更改(如密钥和失效规则)也将可用,而不会对Web项目进行任何更改.如此独立,服务项目也可以与其他项目一起使用,甚至不知道eh-cache.

此时,我的Web项目也将eh-cache用于自己的目的.我对eh-cache不太熟悉,我担心这两个项目在部署时可能会发生冲突.我也没有在eh-cache网站上找到相关信息.

您能否为我提供一些如何最好地配置这两个项目的信息,以便我能达到上述要求?


编辑:

我正在使用Spring,因此我更愿意将它用于我的缓存管理器.

我在context.xml中为使用ehcache的每个jar使用以下内容,例如对于jar 1我有:

<ehcache:annotation-driven cache-manager="ehCacheManager1" />

<bean id="ehCacheManager1" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:ehcache-1.xml" />
</bean>
Run Code Online (Sandbox Code Playgroud)

我有罐子2

<ehcache:annotation-driven cache-manager="ehCacheManager2" />

<bean id="ehCacheManager2" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:ehcache-2.xml" />
</bean>
Run Code Online (Sandbox Code Playgroud)

那么,两个缓存都会起作用吗?我担心ehcache:annotation-driven上次读取的上下文会覆盖它,只有一个缓存可以运行.我错了,还是错过了什么?

Vad*_*kin 3

ConfigurationResourceName 属性用于指定 ehcache 配置文件的位置。在类路径的根目录中搜索资源。它用于支持同一虚拟机中的多个CacheManager。

net.sf.ehcache.configurationResourceName=/name_of_ehcache.xml
Run Code Online (Sandbox Code Playgroud)