2012-06-13 2 views
1

내 JCache 구현으로 Ecache를 사용할 수 있도록 다음 jcache-ehcache 라이브러리를 래퍼로 사용하려고합니다.Ehcache as JCache Implementation in Spring

이 내 받는다는 의존성은 다음과 같습니다

내 Spring 설정 파일에서
<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> 

, 나는 다음과 같은 콩이 :

<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 빈을 만들 때 첫 번째 하나를 제공했다. 오류는 두 번째 매개 변수 (형식이 net.sf.ehcache.jcache.JCacheManager)가 누락 된 경우에 발생합니다.

JCache의 생성자는 다음과 같습니다

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

그래서 당신은 또한 생성자 인자로 JCacheManagerClassLoader를 제공해야합니다.

은 (JCache.java here 참조)

+0

흠 - 나는이 패키지 이름 API- 잘못된보고 있었다 매우 비슷한 있습니다! – totalcruise