首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ehcache作为在Spring中配置的JCache实现

Ehcache作为在Spring中配置的JCache实现
EN

Stack Overflow用户
提问于 2012-06-13 20:28:37
回答 1查看 1.8K关注 0票数 1

我正在尝试使用下面的jcache-ehcache库作为包装器,这样我就可以使用Ecache作为我的JCache实现。

以下是我的maven依赖项:

代码语言:javascript
复制
    <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:

代码语言:javascript
复制
<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区域定义:

代码语言:javascript
复制
  <cache name="userCache" maxElementsInMemory="10000"
  maxElementsOnDisk="0" eternal="false" overflowToDisk="false"
  diskSpoolBufferSizeMB="20" timeToIdleSeconds="0"
  timeToLiveSeconds="0" memoryStoreEvictionPolicy="LFU"
  statistics = "true">
  </cache>

在初始化时,我得到以下错误:

代码语言:javascript
复制
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?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-14 05:55:49

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

JCache的构造函数如下所示:

代码语言:javascript
复制
public JCache(Ehcache ehcache, JCacheManager cacheManager, ClassLoader classLoader) {
    // ...
}

因此,您还需要提供一个JCacheManager和一个ClassLoader作为构造函数参数。

(参见JCache.java here)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11014822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档