2012-06-13 39 views
1

我试图使用下面的jcache-ehcache库作为包装,以便我可以使用Ecache作为我的JCache实现。Ehcache as JCache在Spring中配置的实现

这些都是我的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豆?

感谢

回答

0

net.sf.ehcache.jcache.JCache构造函数有三个参数,但只在创建jcacheUserCache bean时提供的第一个。你得到的错误是关于缺少的第二个参数(类型net.sf.ehcache.jcache.JCacheManager)。

JCache构造是这样的:

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

所以你还需要提供一个JCacheManagerClassLoader构造函数的参数。

(见JCache.java here

+0

嗯 - 我一直在寻找在错误的API - 这些软件包名称是非常相似! – totalcruise