【Arthas案例】某应用依赖两个GAV不同但包含两个相同全限定类名StaticLoggerBinder,引起log4j.Level类找不到异常

3分钟内解决问题

两个不同的GAV依赖冲突,包含相同全限定类名,引起ClassNotFoundException

Maven依赖的三坐标体系GAV(G-groupId,A-artifactId,V-version)

【案例1】某应用依赖两个GAV不同的jar,但包含两个相同全限定类名StaticLoggerBinder,引起log4j.Level类找不到异常

1.完整的异常调用栈【从案发现场找线索】

警察抓犯人,收集线索是破案的关键所在。

2.关键的异常日志

从异常信息中收集有用的线索。

shell 复制代码
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/lihuagang/.m2/repository/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/lihuagang/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: org/apache/log4j/Level
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)

java.lang.NoClassDefFoundError Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class and no definition of the class could be found.

类加载器实例尝试去加载这个类的定义,找不到该类的定义。

3.案发现场的源代码

org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)

  • jad - 反编译指定已加载类的源码
shell 复制代码
[arthas@8]$ jad org.slf4j.LoggerFactory bind

LoggerFactory.java:150,与异常信息对上了。

shell 复制代码
[arthas@8]$ sc -d org.slf4j.impl.StaticLoggerBinder

综上所述,与异常信息完全符合。

4.解决方法

slf4j-log4j12-1.7.30.jar依赖排除掉,搞定。


祝大家玩得开心!ˇˍˇ

广益,杭州

相关推荐
霸道流氓气质1 小时前
阿里云 OSS 从零到实战:概念、配置与 Spring Boot 集成指南
数据库·spring boot·阿里云
可乐ea1 小时前
【Spring Boot + MyBatis|第4篇】MyBatis 动态 SQL:if、where、foreach 使用详解
java·spring boot·后端·sql·mybatis
布局呆星2 小时前
Spring Boot + Redis 缓存实战:@Cacheable、序列化踩坑、缓存一致性,一次讲透
spring boot·redis·缓存
Devin~Y2 小时前
大厂 Java 面试实战:从 Spring Boot 微服务到 AI RAG 音视频平台全链路解析
java·spring boot·redis·spring cloud·微服务·rag·spring ai
我登哥MVP3 小时前
SpringCloud 核心组件解析:服务注册与发现
java·spring boot·后端·spring·spring cloud·java-ee·maven
_未闻花名_3 小时前
PostgreSQL的若干扩展安装和使用
spring boot·postgresql·postgis·timescaledb·pg_cron·pgmq·zhparser
砍材农夫3 小时前
物联网实战:Spring Boot + Netty 搭建 MQTT 统一接入层
java·网络·spring boot·后端·物联网·spring
写代码的小阿帆3 小时前
英语四六级证书审核(SpringBoot+Dify+RPA)
java·spring boot
霸道流氓气质4 小时前
RabbitMQ 从零到实战:概念、配置与 Spring Boot 集成指南
spring boot·rabbitmq·java-rabbitmq
夜郎king4 小时前
SpringBoot 整合 Neo4j 实战:从零搭建经典小说知识图谱完整方案
spring boot·知识图谱·neo4j