1

次の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を正しく初期化する方法について誰かが支援を提供できますか?

ありがとう

4

1 に答える 1

0

のコンストラクターには 3 つの引数がありますが、 Beannet.sf.ehcache.jcache.JCacheの作成時に最初の引数のみを指定しました。jcacheUserCache表示されるエラーは、(タイプの) 2 番目のパラメーターが欠落していることに関するものですnet.sf.ehcache.jcache.JCacheManager

のコンストラクタはJCache次のようになります。

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

JCacheManagerそのため、 aと aClassLoaderをコンストラクターの引数として指定する必要もあります。

(こちらをご覧JCache.javaください

于 2012-06-13T21:55:48.530 に答える