热爱技术,追求卓越
不断求索,精益求精

springboot项目启动报NoSuchMethodError,DefaultListableBeanFactory.getDependencyCompara

springboot项目之前启动正常,今天加了一些代码后出现“Caused by: java.lang.NoSuchMethodError: org.springframework.beans.factory.support.DefaultListableBeanFactory.getDependencyComparator()Ljava/util/Comparator”,报错如下:

ERROR 2018-08-06 10:47:44.962 [SpringApplication.java:842] Application run failed 
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.factory.support.DefaultListableBeanFactory.getDependencyComparator()Ljava/util/Comparator;
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
    at org.springframework.boot.SpringApplication.createApplicationContext(SpringApplication.java:595)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
    at cn.lovecto.promotion.Application.main(Application.java:39)
Caused by: java.lang.NoSuchMethodError: org.springframework.beans.factory.support.DefaultListableBeanFactory.getDependencyComparator()Ljava/util/Comparator;
    at org.springframework.context.annotation.AnnotationConfigUtils.registerAnnotationConfigProcessors(AnnotationConfigUtils.java:151)
    at org.springframework.context.annotation.AnnotationConfigUtils.registerAnnotationConfigProcessors(AnnotationConfigUtils.java:135)
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.<init>(AnnotatedBeanDefinitionReader.java:87)
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.<init>(AnnotatedBeanDefinitionReader.java:70)
    at org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.<init>(AnnotationConfigServletWebServerApplicationContext.java:73)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
    ... 6 more

出现这个原因是由于spring-beans这个jar包的依赖冲突导致的(出现了两个版本的spring-beans)。

maven在依赖某个jar包的时候,会把这个jar包所依赖的其他jar也引入进来。所以在需要屏蔽掉不需要的jar包依版本:

<dependency>
<groupId>cn.lovecto</groupId>
<artifactId>lovecto_common_dao</artifactId>
<version>0.0.1</version>
<exclusions>
    <exclusion>
        <groupId>org.springframework</groupId>
        <artifactId>*</artifactId>
    </exclusion>
</exclusions>
</dependency>

直接把org.springframework相关的都屏蔽掉,让世界清静一会儿。

赞(1)
未经允许不得转载:LoveCTO » springboot项目启动报NoSuchMethodError,DefaultListableBeanFactory.getDependencyCompara

热爱技术 追求卓越 精益求精