问题:
项目启动时报错如下:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/G:/demo/log-loader-demo/target/log-loader-demo/WEB-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/G:/demo/log-loader-demo/target/log-loader-demo/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 [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
解决方案:
1、需要清楚想使用哪种日志工具,log4j 还是 logback ?
2、查看maven依赖树,到项目的pom.xml文件夹所在目录,执行命令:
mvn dependency:tree
如果是idea,可以从底部 Terminal 执行
3、在依赖树结果中搜索你想去除的日志工具依赖,此处我想去除 log4j
查询到 simpleimage 依赖了 log4j,slf4j-log4j12,导致启动时与 logback 冲突
4、去除多余的依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>simpleimage</artifactId>
<version>1.2.3</version>
<!-- 去除log4j相关依赖,防止与logback冲突 -->
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
5、一定要保证依赖中不再含有 log4j 依赖,可以再次执行第二步的步骤进行排查,最终项目启动时,应该不会再报这个错误。
问题排查思路:
1、查看 第四行的提示 http://www.slf4j.org/codes.html#multiple_bindings
发现文中有处理方案(下图上传后变形了,查看时可以点击下放大查看)