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


祝大家玩得开心!ˇˍˇ

广益,杭州

相关推荐
2401_8543910814 分钟前
Spring Boot大学生就业招聘系统的开发与部署
java·spring boot·后端
杨荧41 分钟前
【JAVA开源】基于Vue和SpringBoot的洗衣店订单管理系统
java·开发语言·vue.js·spring boot·spring cloud·开源
2401_857610031 小时前
SpringBoot实现:校园资料分享平台开发指南
服务器·spring boot·php
这孩子叫逆1 小时前
Spring Boot项目的创建与使用
java·spring boot·后端
Jay_fearless2 小时前
Redis SpringBoot项目学习
spring boot·redis
coderWangbuer2 小时前
基于springboot的高校招生系统(含源码+sql+视频导入教程+文档+PPT)
spring boot·后端·sql
Kenny.志3 小时前
2、Spring Boot 3.x 集成 Feign
java·spring boot·后端
sky丶Mamba3 小时前
Spring Boot中获取application.yml中属性的几种方式
java·spring boot·后端
千里码aicood4 小时前
【2025】springboot教学评价管理系统(源码+文档+调试+答疑)
java·spring boot·后端·教学管理系统
程序员-珍4 小时前
使用openapi生成前端请求文件报错 ‘Token “Integer“ does not exist.‘
java·前端·spring boot·后端·restful·个人开发