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

3分钟内解决问题

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

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

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

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

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

完整的异常调用栈

2.关键的异常日志

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

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.

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

java.lang.NoClassDefFoundError

3.案发现场的源代码

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

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

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

[arthas@8]$ sc -d org.slf4j.impl.StaticLoggerBinder

sc -d org.slf4j.impl.StaticLoggerBinder

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

4.解决方法

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


祝大家玩得开心!ˇˍˇ

广益,杭州

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

简放视野

深度思考,简放视野。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值