是否可以使用多个ehcache.xml(在不同的项目中,同样的战争)? [英] Is it possible to use multiple ehcache.xml (in different projects, same war)?

查看:249
本文介绍了是否可以使用多个ehcache.xml(在不同的项目中,同样的战争)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a services project and a web project. I need to have eh-cache in both projects.

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

The idea is that if the service project is updated, it's cache-related changes (like keys and invalidation rules) will also be available, while no changes are made to the web project. Being so independent, the service project can also be used with another projects without them even knowing of eh-cache.

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

At this point, my web project also uses eh-cache for its own purposes. I am not much experienced with eh-cache and I fear that the two projects might clash when deployed together. I also did not find relevant information on eh-cache site.

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

Can you provide me some information how to best configure the two projects, so that I can achieve the above requirements?

编辑:

我使用Spring,因此我更喜欢将它用于我的缓存管理器。

I am using Spring, therefore I will prefer to use it for my cache managers.

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

I am using the following in the context.xml for each jar with ehcache, for instance for jar 1 I have:

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

<bean id="ehCacheManager1" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:ehcache-1.xml" />
</bean>

和jar 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>

那么,两个缓存都会启动并运行吗?我担心 ehcache:annotation-driven 会被最后一次读取上下文覆盖,只有一个缓存可以运行。我错了,还是错过了什么?

So, will both caches be up and working? I fear the ehcache:annotation-driven will get overridden by the last read context and only one cache will be operational. Am I wrong, or missing something?

推荐答案

configurationResourceName属性用于指定ehcache配置文件的位置。在类路径的根中搜索。它用于支持同一VM中的多个CacheManager。

The configurationResourceName property is used to specify the location of the ehcache configuration file.The resource is searched for in the root of the classpath. It is used to support multiple CacheManagers in the same VM.

net.sf.ehcache.configurationResourceName=/name_of_ehcache.xml

这篇关于是否可以使用多个ehcache.xml(在不同的项目中,同样的战争)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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