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


祝大家玩得开心!ˇˍˇ

广益,杭州

相关推荐
Tirzano6 小时前
springsecurity自定义认证
spring boot·spring
bing_1589 小时前
简单工厂模式 (Simple Factory Pattern) 在Spring Boot 中的应用
spring boot·后端·简单工厂模式
天上掉下来个程小白10 小时前
案例-14.文件上传-简介
数据库·spring boot·后端·mybatis·状态模式
sjsjsbbsbsn12 小时前
Spring Boot定时任务原理
java·spring boot·后端
计算机毕设指导612 小时前
基于Springboot学生宿舍水电信息管理系统【附源码】
java·spring boot·后端·mysql·spring·tomcat·maven
计算机-秋大田13 小时前
基于Spring Boot的兴顺物流管理系统设计与实现(LW+源码+讲解)
java·vue.js·spring boot·后端·spring·课程设计
小蒜学长14 小时前
医疗报销系统的设计与实现(代码+数据库+LW)
数据库·spring boot·学习·oracle·课程设计
橘猫云计算机设计15 小时前
基于SSM的《计算机网络》题库管理系统(源码+lw+部署文档+讲解),源码可白嫖!
java·数据库·spring boot·后端·python·计算机网络·毕设
小盼江15 小时前
水果生鲜农产品推荐系统 协同过滤余弦函数推荐水果生鲜农产品 Springboot Vue Element-UI前后端分离 代码+开发文档+视频教程
vue.js·spring boot·ui
坚定信念,勇往无前15 小时前
Spring Boot中整合Flink CDC 数据库变更监听器来实现对MySQL数据库
数据库·spring boot·flink