SLF4J: Class path contains multiple SLF4J bindings.Detected both log4j-over-slf4j.jar AND slf4j-log4

java的日志系统比较复杂,因为经常引用各种jar包,各种jar包中就可能包含各种各样的log组件,有时候这些组件之间相互冲突,但是没有明显的error报错,大家没注意到的时候,就会出现有些日志没有正常打印而大家也不知道问题在哪里,这里将常见的两种隐藏风险在这里总结一下

一:SLF4J: Class path contains multiple SLF4J bindings

报错如下所示:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/apache-tomcat-8.5.47/wtpwebapps/tdsql-conf/WEB-INF/lib/log4j-slf4j-impl-2.13.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/E:/apache-tomcat-8.5.47/wtpwebapps/tdsql-conf/WEB-INF/lib/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

这里很明显的提示有如下的两个jar包的错误

也就是说是log4j-slf4j-impl与slf4j-log4j12两个jar包当中都有binder类,导致冲突,此时我们可以excluede任意一个jar包即可

二:Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path

这个错误就更明显了,明确提示了哪两个jar包有冲突,此时我们只需要exclude其中任意一个即可,但是这里稍微有个点需要注意一下的是,我们exclue的时候,尽量exclude间接引用的jar包,不要exclude显式引用的jar包

猜你喜欢

转载自blog.csdn.net/shyrainxy/article/details/108784702