使用Log4j2 RabbitMQ Appender遇CLASS_NOT_FOUND错误求助
Log4j2 RabbitMQ Appender 启动报错CLASS_NOT_FOUND解决方法
你碰到的ERROR Error processing element RabbitMQ ([Appenders: null]): CLASS_NOT_FOUND和ERROR Unable to locate appender "rabbitmq" for logger config "root"错误,确实是因为项目缺少Log4j2 RabbitMQ Appender的相关依赖。
补充依赖配置
根据你的构建工具,添加对应依赖即可,注意必须保证依赖版本和项目中Log4j2核心版本一致:
Maven
在pom.xml中加入:
<dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-rabbitmq</artifactId> <version>${log4j2.version}</version> </dependency>
将${log4j2.version}替换为你实际使用的Log4j2版本(比如2.20.0)。
Gradle
在build.gradle中加入:
implementation 'org.apache.logging.log4j:log4j-rabbitmq:${log4j2.version}'
同样替换版本号为你项目的Log4j2版本。
额外注意事项
- 确认项目已正确引入Log4j2核心依赖(
log4j-core、log4j-api),且版本和log4j-rabbitmq完全一致,避免版本冲突导致的其他问题。 - 你的配置中
exchange字段为空,这对应RabbitMQ的默认交换器,是合法配置;如果后续需要使用自定义交换器,记得填写正确的交换器名称。
内容的提问来源于stack exchange,提问作者Ternence Hou
相关产品推荐
相关产品推荐

