java - 查找错误的CacheManager Spring ehcache

标签 java spring ehcache

我正在尝试为我的项目使用 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/

相关文章:

javascript - 使用 STOMP 调用一项接受多个参数的服务

java - Spring MVC中如何使用getById方法获取对应的名称?

java - Spring ehcache - 如果返回类型为 List<User>,#root.targetClass 值?

java - 如何使用 Axis 1.0 运行 WSDL2Java?

java - double 值和浮点值比较

java.lang.NoSuchMethodError : org. apache.xml.security.transforms.Transform.init()V

java - 使 EHCache 使未以特定方式访问的元素过期

java - Camel 和缓存生命周期

java - 为我的多线程代码寻求改进建议。我需要12个不同的任务,6个池大小和15分钟的调度程序

Java swing 文件选择器日期过滤器或文件对话框日期过滤器