解决jar包冲突问题:SLF4J: Class path contains multiple SLF4J bindings.

背景:
在ssh框架中使用了slf4j+log4j2日志框架,运行的时候出现警告如下:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/编程/后端开发/作品/IDEA-P2P/p2p-web/target/p2p-web-1.0.0/WEB-INF/lib/log4j-slf4j-impl-2.8.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/E:/编程/后端开发/作品/IDEA-P2P/p2p-web/target/p2p-web-1.0.0/WEB-INF/lib/slf4j-log4j12-1.6.1.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]

分析:
上面的意思大概就是说log4j-slf4j-impl-2.8.2.jar和slf4j-log4j12-1.6.1.jar中的StaticLoggerBinder.class类冲突了
解决办法:
排除slf4j-log4j12-1.6.1.jar,先去你的pom.xml文件中搜索,如果搜索到,删除就是了,关键我要说的是搜索不到的情况,如果搜索不到,说明就是其他包引入的依赖包,接下来的具体操作以IDEA为例,我们直接去Maven依赖中去找,是不容易找到的,我们可以使用如下的做法寻找到底是哪个包引入的jar包:
在这里插入图片描述在这里插入图片描述这样我们就找到了slf4j-log4j12-1.6.1.jar包是zkclient这个jar包引入的,我们可以使用下面的做法排除slf4j-log4j12-1.6.1.jar包:

<!-- zookeeper客户端依赖 -->
<dependency>
    <groupId>com.101tec</groupId>
    <artifactId>zkclient</artifactId>
    <!--排除这个slf4j-log4j12-->
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>

这样项目在启动就不会出现警告了

发布了177 篇原创文章 · 获赞 24 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_42449963/article/details/105228510