升级到 SpringBoot-2.1.0 出错(spring-data, elasticsearch-6.4.2)ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z

 

 

Exception in thread "main" java.lang.AbstractMethodError: org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z
 

Connected to the target VM, address: '127.0.0.1:62964', transport: 'socket'
Exception in thread "main" java.lang.AbstractMethodError: org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z
    at org.springframework.context.event.GenericApplicationListenerAdapter.supportsSourceType(GenericApplicationListenerAdapter.java:81)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.supportsEvent(AbstractApplicationEventMulticaster.java:295)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:225)
    at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:196)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:133)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)

 


原因在于:ConfigFileApplicationListener 没有实现 SmartApplicationListener 接口的方法:

public class ConfigFileApplicationListener
      implements EnvironmentPostProcessor, SmartApplicationListener, Ordered {
supportsSourceType() // 没实现

 

根本原因在于版本依赖错误


[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.1.0.RELEASE:compile
.....

[INFO] |  \- org.springframework.amqp:spring-rabbit:jar:2.1.0.RELEASE:compile

[INFO] |     +- org.springframework:spring-context:jar:5.0.8.RELEASE:compile

查看 parent 项目pom.xml,发现两处版本定义不一致:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.0.RELEASE</version>
    <relativePath/>
</parent>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.0.4.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

解决:

<parent> 和 <dependency> 只需要二先一,定义了parent就不需要再加dependency