我正在尝试为我的项目使用 spring 注解配置 ehcache,但出现此异常:
无法将属性“cacheManager”的类型 [org.springframework.cache.ehcache.EhCacheCacheManager] 的值转换为所需类型 [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>
我做错了什么?如果我将 rg.springframework.cache.ehcache.EhCacheCacheManager 更改为 net.sf.ehcache.CacheManager 我会得到另一个异常。
感谢您给我的任何帮助。
最诚挚的问候。
最佳答案
您正在手动创建一个 Spring CacheManager,并且它被注释驱动
机制隐式使用(由于它是“cacheManager”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" />
关于java - 查找错误的CacheManager Spring ehcache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25531841/