maven项目启动报错:SLF4J: Class path contains multiple SLF4J bindings.

SringBoot的Application启动报错:

1 SLF4J: Class path contains multiple SLF4J bindings.
2 SLF4J: Found binding in [jar:file:/G:/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
3 SLF4J: Found binding in [jar:file:/G:/.m2/repository/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
4 SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
5 SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

原因:logback-classic包和slf4j包冲突。 

解决方法:

找到哪个依赖引入了logback-classic,然后用依赖排除标签排除掉。

具体解决:

其中slf4j-log4j12包是我在pom中引入的,说明logback-classic包是其他依赖中引用的。在pom文件的Depency Hierarchy页签中,找到:

是spring-boot-starter-jdbc包引入的。

(也可以用mvn dependency:tree 命令查看依赖关系)

 在pom中排除掉:

 1 <dependency>
 2     <groupId>org.springframework.boot</groupId>
 3     <artifactId>spring-boot-starter-jdbc</artifactId>
 4 
 5         <!--排除-->
 6     <exclusions>
 7          <exclusion> 
 8          <groupId>ch.qos.logback</groupId>
 9          <artifactId>logback-classic</artifactId>
10         </exclusion>
11     </exclusions>
12 
13 </dependency>

 

posted @ 2018-08-16 16:15  夏天的尾巴%  阅读(11936)  评论(1编辑  收藏  举报