문제

I am trying to use the following jcache-ehcache library to as a wrapper so that I can use Ecache as my JCache implementation.

These are my maven dependancies:

    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache</artifactId>
        <version>2.1.0</version>
        <type>pom</type>
    </dependency>

    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache-jcache</artifactId>
        <version>1.4.0-beta1</version>
    </dependency>

In my Spring configuration file, I have the following beans:

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="shared" value="true"/>
</bean>


<bean id="userCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
    <property name="cacheName" value="userCache"/>
    <property name="cacheManager" ref="cacheManager"/>
    <property name="diskPersistent" value="false"/>
</bean>

<bean id="jcacheUserCache" class="net.sf.ehcache.jcache.JCache">
    <constructor-arg index="0" ref="userCache"/>
</bean>

And my Ehcache.xml (on classpath root) file contains the userCache region definition:

  <cache name="userCache" maxElementsInMemory="10000"
  maxElementsOnDisk="0" eternal="false" overflowToDisk="false"
  diskSpoolBufferSizeMB="20" timeToIdleSeconds="0"
  timeToLiveSeconds="0" memoryStoreEvictionPolicy="LFU"
  statistics = "true">
  </cache>

On initialization, I get the following error:

Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jcacheUserCache' defined in class path resource [application-context.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [net.sf.ehcache.jcache.JCacheManager]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments?

Can anyone provide any assistance with how to correctly initialise this jCacheUserCache bean?

Thanks

도움이 되었습니까?

해결책

The constructor of net.sf.ehcache.jcache.JCache has three arguments, but you only provided the first one when creating the jcacheUserCache bean. The error you get is about the missing second parameter (of type net.sf.ehcache.jcache.JCacheManager).

The constructor of JCache looks like this:

public JCache(Ehcache ehcache, JCacheManager cacheManager, ClassLoader classLoader) {
    // ...
}

So you also need to provide a JCacheManager and a ClassLoader as constructor arguments.

(see JCache.java here)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top