最近寫新項目用maven引入sl4j老是提示這個錯誤,查了一下一些是由於引入的包衝突。好比:https://www.jianshu.com/p/b562b7ff499fjavascript
這裏寫的比較詳細:java
slf4j-log4j12.jar (for log4j logging), slf4j-jdk14.jar (for Java logging), slf4j-jcl.jar (if you’re using Commons logging) logback-classic.jar (for logback logging). 以上的包引入一種便可
個人一開始覺得是包衝突,而後經過依賴樹命令發現是一個低級錯誤,引入的sl4j包的scope是test級別的,而後運行就出錯了。直接去掉便可,不寫<scope>標籤默認compile級別。mysql
D:\work\eclipse8\abc\share>mvn dependency:tree [INFO] Scanning for projects... [INFO] [INFO] ---------------------------< xgame:sharing >---------------------------- [INFO] Building sharing 0.0.1 [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ sharing --- [INFO] xgame:sharing:jar:0.0.1 [INFO] +- io.netty:netty-all:jar:4.1.38.Final:compile [INFO] +- commons-lang:commons-lang:jar:2.6:compile [INFO] +- org.mybatis:mybatis:jar:3.2.7:compile [INFO] +- com.google.protobuf:protobuf-java:jar:2.5.0:compile [INFO] +- com.google.guava:guava:jar:19.0:compile [INFO] +- commons-codec:commons-codec:jar:1.13:compile [INFO] +- commons-beanutils:commons-beanutils:jar:1.8.3:compile [INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile [INFO] +- com.lmax:disruptor:jar:3.3.7:compile [INFO] +- org.quartz-scheduler:quartz:jar:2.2.3:compile [INFO] | +- c3p0:c3p0:jar:0.9.1.1:compile [INFO] | \- org.slf4j:slf4j-api:jar:1.7.7:compile [INFO] +- net.sf.json-lib:json-lib:jar:jdk15:2.4:compile [INFO] | +- commons-collections:commons-collections:jar:3.2.1:compile [INFO] | \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile [INFO] +- com.typesafe:config:jar:1.3.4:compile [INFO] +- mysql:mysql-connector-java:jar:5.1.8:compile [INFO] \- org.slf4j:slf4j-log4j12:jar:1.7.26:test [INFO] \- log4j:log4j:jar:1.2.17:test [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.907 s [INFO] Finished at: 2019-08-16T00:21:52+08:00 [INFO] ------------------------------------------------------------------------
查maven依賴版本的時候,默認帶了scope爲test。sql
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.26</version> <scope>test</scope> </dependency>