我正在尝试使用下面的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:
<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?
谢谢
发布于 2012-06-14 05:55:49
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 here)
https://stackoverflow.com/questions/11014822
复制相似问题