简体   繁体   English

从春季创建EhCache缓存时出现问题

[英]problem creating an EhCache Cache from spring

Reading the javadoc for EhCacheManagerFactoryBean and EhCacheFactoryBean I figured that: 阅读EhCacheManagerFactoryBeanEhCacheFactoryBean的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"/>

would create a cache that I then can @Autowired in. But I must be missing something because this is what I get: 会创建一个我可以@Autowired进入的缓存。但是我必须缺少一些东西,因为这是我得到的:

Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'locationCache' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; 向类org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException的侦听器实例发送上下文初始化事件的异常:在ServletContext资源[/WEB-INF/applicationContext.xml中定义的名称为'locationCache'的bean创建时出错]:调用init方法失败; nested exception is java.lang.NoSuchMethodError: net.sf.ehcache.Cache.(Ljava/lang/String;ILnet/sf/ehcache/store/MemoryStoreEvictionPolicy; ZLjava/lang/String;ZJJZJLnet/sf/ehcache/event/RegisteredEventListeners; Lnet/sf/ehcache/bootstrap/BootstrapCacheLoader;II)V 嵌套的异常是java.lang.NoSuchMethodError:net.sf.ehcache.Cache。 Lnet / sf / ehcache / bootstrap / BootstrapCacheLoader; II)V

I've tried ehcache 1.7.2, 1.6.2 and 1.5.0. 我已经尝试过ehcache 1.7.2、1.6.2和1.5.0。

It works if I specify <cache name="locationCache" /> in ehcache.xml but I prefer to have my configuration done in applicationsContext.xml 如果我在ehcache.xml中指定<cache name="locationCache" /> ,它会起作用,但我希望在appsContext.xml中完成配置

<cache name="locationCache" /> 

The missing constructor belongs to Ehcache 1.3, and it still exists in the newer versions. 缺少的构造函数属于Ehcache 1.3,在新版本中仍然存在。 May be, you have some problem with dependecnies. 可能是,您在依赖方面有一些问题。 If you use maven, try mvn dependency:tree -Dverbose=true and look for conflicts. 如果使用maven,请尝试使用mvn dependency:tree -Dverbose=true并查找冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM