错误的CacheManager被查找Spring ehcache

时间:2014-08-27 15:58:59

标签: java spring ehcache

我正在尝试为我的项目配置带有spring anotations的ehcache,我得到了这个例外:

无法将[org.springframework.cache.ehcache.EhCacheCacheManager]类型的值转换为属性'cacheManager'所需的类型[net.sf.ehcache.CacheManager]

我的上下文应用程序文件是这样的:

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/util
   http://www.springframework.org/schema/util/spring-util-3.0.xsd       
   http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
   http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-        spring-1.1.xsd">
<ehcache:annotation-driven/>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"     p:cache-manager-ref="ehcache" />
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="/WEB-INF/ehcache.xml"/>
</beans>

我做错了什么?如果我为net.sf.ehcache.CacheManager更改了rg.springframework.cache.ehcache.EhCacheCacheManager,我会得到另一个例外。

感谢您给我的任何帮助。

最诚挚的问候。

1 个答案:

答案 0 :(得分:1)

您正在手动创建Spring CacheManager,并且annotation-driven机制隐式使用它(由于它&#34; cacheManager&#34; id)。注释机制实际上会为您做到这一点,但它需要底层的缓存实现。因此,请将代码更改为以下内容:

<ehcache:annotation-driven/>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" 
    p:configLocation="/WEB-INF/ehcache.xml"/>

注意:你可以摆脱

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"     p:cache-manager-ref="ehcache" />
相关问题