springehcachespring-cachejcache

XML cacheManger bean : Multiple CachingProviders error


hello so I used to use one single cache provider to manage my caches but now I have to use more than one and I'm getting some problem in init my bean in fact I get this error :

is there any possibility to define a specific provider for my XML bean?

   Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jCacheManager' defined in class path resource [default-beans.xml]: Invocation of init method failed; nested exception is javax.cache.CacheException: Multiple CachingProviders have been configured when only a single CachingProvider is expected

my bean

 <bean id="jCacheManager" class="org.springframework.cache.jcache.JCacheManagerFactoryBean">
          <property name="cacheManagerUri" value="classpath:ehcache.xml"/>
        </bean>
        <bean id="DefaultCacheManager" class="org.springframework.cache.jcache.JCacheCacheManager" scope = "singleton">
          <property name="cacheManager" ref="jCacheManager" />
        </bean>

Solution

  • <bean id="CacheProvider"
    class="org.ehcache.jsr107.EhcacheCachingProvider" />
    <bean id="CacheManager"
        class="org.ehcache.jsr107.Eh107CacheManager"
        factory-bean="CacheProvider" factory-method="getCacheManager">
        <constructor-arg
            value='#{ new org.springframework.core.io.ClassPathResource("/ehcache.xml").getURI()}' />
        <constructor-arg
            value="#{ getClass().getClassLoader()}" />
    </bean>