异常如下:
原因可能是ehcache的包版本不对,但是pom.xml中确实是正确的版本,应该是eclipse运行junit时用的是另一个版本的包。
可以这样解决:
Run -> Debug Configurations... -> 选中你的junit任务 -> Classpath -> Bootstrap Entries中增加正确的jar包。如图
[img]http://dl.iteye.com/upload/attachment/0081/2031/06120e7d-0781-303e-b41b-d43f36c93af1.jpg[/img]
Caused by: java.lang.NoSuchMethodError: net.sf.ehcache.Cache.<init>(Ljava/lang/String;ILnet/sf/ehcache/store/MemoryStoreEvictionPolicy;ZLjava/lang/String;ZJJZJLnet/sf/ehcache/event/RegisteredEventListeners;Lnet/sf/ehcache/bootstrap/BootstrapCacheLoader;II)V
at org.springframework.cache.ehcache.EhCacheFactoryBean.createCache(EhCacheFactoryBean.java:354)
at org.springframework.cache.ehcache.EhCacheFactoryBean.afterPropertiesSet(EhCacheFactoryBean.java:331)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 38 more
原因可能是ehcache的包版本不对,但是pom.xml中确实是正确的版本,应该是eclipse运行junit时用的是另一个版本的包。
可以这样解决:
Run -> Debug Configurations... -> 选中你的junit任务 -> Classpath -> Bootstrap Entries中增加正确的jar包。如图
[img]http://dl.iteye.com/upload/attachment/0081/2031/06120e7d-0781-303e-b41b-d43f36c93af1.jpg[/img]
解决EHCache版本冲突

本文介绍了一种在Spring框架中使用EHCache时遇到版本冲突的问题及解决方案。具体表现为NoSuchMethodError错误,原因是Junit测试中加载了错误版本的EHCache库。通过调整Eclipse的调试配置,正确设置Classpath中的Bootstrap Entries,指定了正确的EHCache jar包路径来解决问题。
2257

被折叠的 条评论
为什么被折叠?



