[英]Ehcache as JCache Implementation configured in Spring
我正在嘗試使用以下jcache-ehcache庫作為包裝器,以便可以將Ecache用作我的JCache實現。
這些是我的專家依賴:
<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:
<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
bean的幫助嗎?
謝謝
net.sf.ehcache.jcache.JCache
的構造net.sf.ehcache.jcache.JCache
具有三個參數,但是在創建jcacheUserCache
bean時僅提供了第一個參數。 您得到的錯誤是關於缺少第二個參數(類型為net.sf.ehcache.jcache.JCacheManager
)。
JCache
的構造函數如下所示:
public JCache(Ehcache ehcache, JCacheManager cacheManager, ClassLoader classLoader) {
// ...
}
因此,您還需要提供JCacheManager
和ClassLoader
作為構造函數參數。
( 在此處查看JCache.java
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.