【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依赖排除掉,搞定。


祝大家玩得开心!ˇˍˇ

广益,杭州

相关推荐
汤姆yu几秒前
基于SpringBoot的人工智能学习网站
spring boot·后端·学习·人工智能学习
+VX:Fegn08958 分钟前
计算机毕业设计|基于springboot + vue服装商城系统(源码+数据库+文档)
数据库·vue.js·spring boot
JIngJaneIL10 分钟前
基于Java在线考试管理系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot
计算机毕设指导613 分钟前
基于微信小程序的篮球场馆预订系统【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
JIngJaneIL14 分钟前
基于Java音乐管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
毕设源码-朱学姐16 分钟前
【开题答辩全过程】以 驾校信息管理系统为例,包含答辩的问题和答案
java·spring boot
RainbowSea11 小时前
从 Spring Boot 2.x 到 3.5.x + JDK21:一次完整的生产环境迁移实战
java·spring boot·后端
奶油松果11 小时前
Springboot自动装配 - redis和redission
java·spring boot·redis
千寻技术帮11 小时前
10413_基于Springboot的智慧养老院管理系统
spring boot·mysql·源码·安装·文档·ppt·养老院
VX:Fegn089512 小时前
计算机毕业设计|基于Java人力资源管理系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot·后端·课程设计