Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

java - Is it possible to use multiple ehcache.xml (in different projects, same war)?

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

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.

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?


Edit:

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

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>

and for jar 2 I have

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

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...