Receiver class org.springframework.boot.context.config.ConfigFileApplicationListener does not define

Spring Boot集成Dubbo配置监听器异常

错误如下:

Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at com.taobao.pandora.boot.loader.LaunchRunner.run(LaunchRunner.java:32)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.AbstractMethodError: Receiver class org.springframework.boot.context.config.ConfigFileApplicationListener does not define or inherit an implementation of the resolved method abstract supportsSourceType(Ljava/lang/Class;)Z of interface org.springframework.context.event.SmartApplicationListener.
	at org.springframework.context.event.GenericApplicationListenerAdapter.supportsSourceType(GenericApplicationListenerAdapter.java:79)
	at org.springframework.context.event.AbstractApplicationEventMulticaster.supportsEvent(AbstractApplicationEventMulticaster.java:282)
	at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:214)
	at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:185)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:125)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:119)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:342)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)

Environment

  • Dubbo version: 2.7.1
  • Operating System version: mac 10.14
  • Java version: 12
  • SpringBoot version: 2.1.4.RELEASE

Steps to reproduce this issue

  1. Create Spring boot project
  2. Add dependency dubbo 2.7.1
  3. Start Application

If there is an exception, please attach the exception trace:

解决方法

Root cause is some one dependency low version spring-context, when dependency dubbo, must exclusion spring-context,not spring, such like:

        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo</artifactId>
            <version>${dubbo.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

 from Spring 3.x or 4.x you need to exclude spring-context instead of spring.

当出现 `Exception in thread "main" java.lang.AbstractMethodError: Receiver class org.springframework.boot.logging.logback.RootLogLevelConfigurator does not define or inherit an implementation of the resolved method` 错误时,通常与Spring Boot的日志配置相关。此错误表明某个类缺少了预期的方法实现,可能是由于依赖版本不兼容或冲突导致的。 ### 原因分析 1. **日志框架版本不兼容**:Spring Boot默认使用Logback作为日志框架。如果手动引入了其他日志实现(如Log4j或旧版本的Logback),可能会导致类冲突或方法缺失。 2. **依赖冲突**:项目中可能引入了多个版本的Spring Boot或日志相关依赖,导致运行时加载了错误的类版本。 3. **Spring Boot版本问题**:某些Spring Boot版本可能存在与日志配置相关的Bug,尤其是在升级Spring Boot版本后未同步其他依赖时。 ### 解决方案 1. **检查依赖版本一致性**: - 确保所有Spring Boot相关依赖使用相同的版本号。 - 使用Maven的`exclusion`标签排除冲突的日志依赖,例如: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> ``` 2. **排除多余日志实现**: - 如果引入了其他日志框架(如Log4j),应确保它们不会与Logback冲突。可以通过`pom.xml`或`build.gradle`配置排除不必要的日志依赖。 3. **使用Maven Enforcer Plugin检测依赖冲突**: - 在`pom.xml`中引入Maven Enforcer Plugin以检测依赖收敛问题: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.0.0-M3</version> <executions> <execution> <id>enforce</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <DependencyConvergence /> </rules> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` 该插件会检测依赖树中的版本冲突并提示具体问题[^4]。 4. **清理并重新构建项目**: - 使用`mvn clean install`或`gradle clean build`命令清理并重新构建项目,确保所有依赖正确下载和解析。 5. **升级Spring Boot版本**: - 如果问题仍然存在,考虑升级到最新的Spring Boot稳定版本,通常新版本会修复已知的日志配置问题。 6. **自定义日志配置文件**: - 如果需要自定义日志配置,确保使用正确的Logback配置文件格式,并避免使用已被弃用的类或方法。 ### 示例:排除Logback依赖 ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </exclusion> </exclusions> </dependency> ``` ### 示例:Maven Enforcer Plugin配置 ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.3.1</version> <executions> <execution> <id>enforce</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <DependencyConvergence /> </rules> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` 通过以上方法,可以有效解决`AbstractMethodError`与日志配置相关的问题,并确保Spring Boot项目的依赖一致性。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JAVA程序哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值