阅读EhCacheManagerFactoryBean和EhCacheFactoryBean的javadoc时,我发现:
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="classpath:ehcache.xml"/>
<bean id="locationCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean"
p:cacheManager-ref="cacheManager"
p:cacheName="locationCache"/>
会创建一个我可以@Autowired进入的缓存。但是我必须缺少一些东西,因为这是我得到的:
将上下文初始化事件发送到类org.springframework.web.context.ContextLoaderListener的侦听器实例的异常
org.springframework.beans.factory.BeanCreationException:创建在ServletContext资源[/WEB-INF/applicationContext.xml]中定义的名称为“ locationCache”的bean时出错:调用init方法失败;嵌套的异常是java.lang.NoSuchMethodError:net.sf.ehcache.Cache。 Lnet / sf / ehcache / bootstrap / BootstrapCacheLoader; II)V
我已经尝试过ehcache 1.7.2、1.6.2和1.5.0。
如果我在ehcache.xml中指定
<cache name="locationCache" />
,它可以工作,但我更喜欢在applicationsContext.xml中完成配置<cache name="locationCache" />
最佳答案
缺少的构造函数属于Ehcache 1.3,在新版本中仍然存在。可能是,您在依赖方面有一些问题。如果使用Maven,请尝试mvn dependency:tree -Dverbose=true
并查找冲突。
关于java - 从 Spring 创建EhCache缓存时出现问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2061107/