java.lang.NoSuchMethodError: org.springframework.cache.ehcache.EhCacheFactoryBean.setMaxEntriesLocal
来源:互联网 发布:数据库简答题 编辑:程序博客网 时间:2024/06/05 15:51
遇到的问题:Spring Boot工程,引入ehCache作为2级缓存,在eclipse中运行main方法启动工程没有问题,但是在命令行中运行 mvn spring-boot:run时,却出错了,报错如下:
...org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehCacheFactoryBean' defined in class path resource [com/xxxx/xxxx/CacheConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.ehcache.EhCacheFactoryBean]: Factory method 'ehCacheFactoryBean' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.cache.ehcache.EhCacheFactoryBean.setMaxEntriesLocalHeap(J)V...来看看工程中的代码:
@Autowiredprivate EhCacheFactoryBean ehCacheFactoryBean;我在实现缓存的类中自动注入了一个EhCacheFactoryBean,接着看看EhCacheFactoryBean的源码:
public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBean<Ehcache>, BeanNameAware, InitializingBean { ...}也就是说EhCacheFactoryBean是CacheConfiguration的一个子类,在Spring 注入Bean的时候,先注入父类,再注入子类,而且错误提示
Error creating bean with name 'ehCacheFactoryBean' defined in class path resource [com/xxxx/xxxx/CacheConfiguration.class]说明Spring没有把CacheConfiguration注到容器中,那么问题来了
1.CacheConfiguration为什么没有被注入?CacheConfiguration位于 net.sf.ehcache.config包下,这样很有可能是系统中存在两个CacheConfiguration类,导致了冲突,所以注入失败,在查看maven引入的jar包时,发现了一个ehcache-2.10.2.jar和ehcache-core-2.4.3.jar,再看包里面的内容时,发现都有CacheConfiguration类,所以必然是同名的类导致了冲突。
2.为什么会引入了两个ehcache的包?接着就去查看了pom,原来是在引入hibernate二级缓存依赖时引入了ehcache-core包:
<dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-ehcache</artifactId></dependency>
解决办法就是把ehcache-core包排除掉就可以了
<dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-ehcache</artifactId> <exclusions> <exclusion> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-core</artifactId> </exclusion> </exclusions></dependency>
但是为什么在有jar包冲突的情况下,在eclipse下运行会不报错,在命令行下执行会报错呢?小白坐等大神的解答呀。
阅读全文
2 0
- java.lang.NoSuchMethodError: org.springframework.cache.ehcache.EhCacheFactoryBean.setMaxEntriesLocal
- org.springframework.cache.ehcache.EhCacheManagerFactoryBean
- java.lang.NoSuchMethodError: org.springframework.beans.BeanUtils.instantiateClass
- java.lang.NoSuchMethodError: org.springframework.web.context.support.XmlWebApplicationContext.getEnv
- java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.setId
- java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlReaderContext.getResourceLoade
- java.lang.NoSuchMethodError: org.springframework.core.GenericTypeResolver.resolveTypeArguments
- java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.forName(Ljava
- 关于java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.makeAccessible
- 【exception】java.lang.NoSuchMethodError: org.springframework.beans.Beans.BeanUtils
- 关于java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.makeAccessible
- java.lang.NoSuchMethodError:org.springframework.core.GenericTypeResolver.resolve
- java.lang.NoSuchMethodError: org.springframework.core.io.ResourceEditor错误
- error java.lang.NoSuchMethodError: org.springframework.core.convert.support.PropertyTypeDescriptor
- java.lang.NoSuchMethodError: org.springframework.beans.MutablePropertyValues.add
- java.lang.NoSuchMethodError: org.springframework.beans.MutablePropertyValues.a
- java.lang.NoSuchMethodError: org.springframework.beans.factory.support.RootBeanDefinition.<init>
- java.lang.NoSuchMethodError: org.springframework.core.io.ResourceEditor错误
- LoggerFactory打印代码错误日志
- redis与一些数据库及软件之间的区别
- java中的接口与工厂
- Bootstrap Table 中文文档(完整翻译版)
- linux下进程和线程状态查看
- java.lang.NoSuchMethodError: org.springframework.cache.ehcache.EhCacheFactoryBean.setMaxEntriesLocal
- sql语句实现查询实例
- 二叉搜索树转有序双向链表
- 迁移学习 Transfer learning
- Weblogic学习(二) Linux下安装Weblogic11g
- Android根据图片Uri获取图片绝对路径
- lnmp1.3环境下thinkphp3.2配置pathinfo模式
- Nginx+Tomcat 集群配置
- 错误 libpam enabled but missing——编译openVPN时出错