1
votes

I have a multi module project with all the modules defining their cache configurations in their own ehcache.xml. This use case is addressed by the now unmaintained "ehcache-spring-annotations" project through a configuration like this:

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

I tried something similar in Spring's Cache Abstraction.

    <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"/>

However, I ran into this exception:

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

Can someone please explain what is the correct way to configure Spring's Cache Abstraction for EhCache in a multi module project?

2
Raised this as an issue in Spring project. - James Selvakumar

2 Answers

0
votes

If you want multiple CacheManagers in single Spring context, you will have to define multiple beans and add qualifiers to them to be able to differentiate them based on some context.

So there is nothing specific to caching here, it is the classical multiple beans of the same type in Spring.

0
votes

In the end, we moved away from ehcache.xml and started using Java based configuration for our caches which solved this problem.