idea项目启动报错,日志包冲突slf4j和logback冲突
报错如下
slf4j: found binding in [jar:file:/e:/maven_dev/maven_3/apache-maven-3.5.2/repo/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/staticloggerbinder.class] slf4j: found binding in [jar:file:/e:/maven_dev/maven_3/apache-maven-3.5.2/repo/org/slf4j/slf4j-log4j12/1.7.29/slf4j-log4j12-1.7.29.jar!/org/slf4j/impl/staticloggerbinder.class] 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:/e:/maven_dev/maven_3/apache-maven-3.5.2/repo/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
slf4j: found binding in [jar:file:/e:/maven_dev/maven_3/apache-maven-3.5.2/repo/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/staticloggerbinder.class]
slf4j: found binding in [jar:file:/e:/maven_dev/maven_3/apache-maven-3.5.2/repo/org/slf4j/slf4j-log4j12/1.7.29/slf4j-log4j12-1.7.29.jar!/org/slf4j/impl/staticloggerbinder.class]
在pom.xml中添加
<dependency> <groupid>ch.qos.logback</groupid> <artifactid>logback-classic</artifactid> <version>1.2.3</version> </dependency>
<dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> <!--解决日志包冲突--> <exclusions> <exclusion> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> </exclusion> </exclusions> </dependency>
根据自己的版本进行调整
<!--添加zookeeper版本,与虚拟机一致--> <dependency> <groupid>org.apache.zookeeper</groupid> <artifactid>zookeeper</artifactid> <version>3.4.9</version> <exclusions> <exclusion> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> </exclusion> </exclusions> </dependency>
启动ok!!!
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论