Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/mavanRepo/org/slf4j/slf4j-log4j12/1.7.29/slf4j-log4j12-1.7.29.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/mavanRepo/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.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.slf4j.impl.Log4jLoggerFactory]
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/opt/mavanRepo/org/slf4j/slf4j-log4j12/1.7.29/slf4j-log4j12-1.7.29.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory
报错
一眼就能看到:classpath上有多个SLF4J的jar绑定,哪两个jar呢?slf4j-log4j12-1.7.29.jar和logback-classic-1.2.3.jar。
官方回答
点开上面日志中的链接,官方回答如下,我们只需要看第一句即可,即SLF4J API只能和一个日志框架绑定,如果当前classpath上有不止一个日志框架的jar,那么会提示警告并列出所有的日志框架的jar信息。所以显然是因为我们导入的jar中有多个日志框架,就是上面列出的slf4j-log4j12-1.7.30.jar和logback-classic-1.2.3.jar,从pom.xml中排除即可。
我这个错误是因为在zookeeper3.7.0里面自带了slf4j这个jar包,会和starter中的冲突,需要排除
<!--zookeeper3.7.0里面自带了slf4j这个jar包,会和starter中的冲突,需要排除-->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.7.0</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
在依赖
图中就可以看得见