Ehcache как реализация JCache, настроенная в Spring

Я пытаюсь использовать следующую библиотеку jcache-ehcache в качестве оболочки, чтобы я мог использовать Ecache в качестве реализации JCache.

Это мои зависимости maven:

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

В моем файле конфигурации Spring у меня есть следующие компоненты:

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

И мой файл Ehcache.xml (в корне пути к классам) содержит определение области userCache:

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

При инициализации получаю следующую ошибку:

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?

Может ли кто-нибудь помочь с правильной инициализацией этого компонента jCacheUserCache?

Спасибо


person totalcruise    schedule 13.06.2012    source источник


Ответы (1)


Конструктор net.sf.ehcache.jcache.JCache имеет три аргумента, но вы предоставили только первый при создании bean-компонента jcacheUserCache. Вы получаете сообщение об отсутствующем втором параметре (типа net.sf.ehcache.jcache.JCacheManager).

Конструктор JCache выглядит так:

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

Поэтому вам также необходимо предоставить JCacheManager и ClassLoader в качестве аргументов конструктора.

(см. JCache.java здесь)

person jeha    schedule 13.06.2012
comment
Хм - я смотрел не на тот API - эти имена пакетов очень похожи! - person totalcruise; 14.06.2012