2019年3月找实习时,曾被阿里面试官问到一个问题,如何解决依赖冲突?当时有点懵,瞎答了一通!
今天在做项目的时候切实的遇到了这个问题,所以记录一下。
1.问题描述:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in xxxxx
SLF4J: Found binding in xxxxx
注:项目使用springboot框架。
2.解决
1.使用eclipse的Dependency Hierarchy功能可以对pom.xml中定义的jar依赖进行可视化展示。 如下:
2.在pom.xml中加入排除代码:
<dependency>
<groupId>com.sap.xs2.security</groupId>
<artifactId>java-container-security-api</artifactId>
<version>0.26.4</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
注意:此处有两个选择,可以自行选择
1.去除slf4j,使用lagback(我的做法)这种方式需要在pom.xml文件中找到所有依赖了slf4j的组件,在中使用排除slf4j的依赖。
2,去除logback,使用slf4j
在使用排除logback的依赖,做法同上。