尝试在java项目中运行单元测试时出现以下错误:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/me/.m2/repository/org/slf4j/slf4j-log4j12/1.5.8/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/me/.m2/repository/ch/qos/logback/logback-classic/1.0.6/logback-classic-1.0.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See slf4j.org/… for an explanation.
我的pom.xml有以下依赖关系:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
我的mvn依赖关系树:
[INFO] +- junit:junit:jar:4.8.1:test
[INFO] +- storm:storm:jar:0.9.0.1:provided
[INFO] | +- storm:storm-console-logging:jar:0.9.0.1:provided
[INFO] | +- storm:storm-core:jar:0.9.0.1:provided
[INFO] | | +- org.clojure:clojure:jar:1.4.0:provided
[INFO] | | +- commons-io:commons-io:jar:1.4:provided
[INFO] | | +- org.apache.commons:commons-exec:jar:1.1:provided
[INFO] | | +- storm:libthrift7:jar:0.7.0-2:provided
[INFO] | | | +- commons-lang:commons-lang:jar:2.5:provided
[INFO] | | | \- javax.servlet:servlet-api:jar:2.5:provided
[INFO] | | +- clj-time:clj-time:jar:0.4.1:provided
[INFO] | | | \- joda-time:joda-time:jar:2.0:provided
[INFO] | | +- com.netflix.curator:curator-framework:jar:1.0.1:provided
[INFO] | | | +- com.netflix.curator:curator-client:jar:1.0.1:provided
[INFO] | | | \- org.apache.zookeeper:zookeeper:jar:3.3.3:provided
[INFO] | | | \- jline:jline:jar:0.9.94:provided
[INFO] | | +- backtype:jzmq:jar:2.1.0:provided
[INFO] | | +- com.googlecode.json-simple:json-simple:jar:1.1:provided
[INFO] | | +- compojure:compojure:jar:1.1.3:provided
[INFO] | | | +- org.clojure:core.incubator:jar:0.1.0:provided
[INFO] | | | +- org.clojure:tools.macro:jar:0.1.0:provided
[INFO] | | | +- clout:clout:jar:1.0.1:provided
[INFO] | | | \- ring:ring-core:jar:1.1.5:provided
[INFO] | | | \- commons-fileupload:commons-fileupload:jar:1.2.1:provided
[INFO] | | +- hiccup:hiccup:jar:0.3.6:provided
[INFO] | | +- ring:ring-devel:jar:0.3.11:provided
[INFO] | | | \- clj-stacktrace:clj-stacktrace:jar:0.2.2:provided
[INFO] | | +- ring:ring-jetty-adapter:jar:0.3.11:provided
[INFO] | | | +- ring:ring-servlet:jar:0.3.11:provided
[INFO] | | | +- org.mortbay.jetty:jetty:jar:6.1.26:provided
[INFO] | | | | \- org.mortbay.jetty:servlet-api:jar:2.5-20081211:provided
[INFO] | | | \- org.mortbay.jetty:jetty-util:jar:6.1.26:provided
[INFO] | | +- org.clojure:tools.logging:jar:0.2.3:provided
[INFO] | | +- org.clojure:math.numeric-tower:jar:0.0.1:provided
[INFO] | | +- storm:carbonite:jar:1.5.0:provided
[INFO] | | | \- com.esotericsoftware.kryo:kryo:jar:2.17:provided
[INFO] | | | +- com.esotericsoftware.reflectasm:reflectasm:jar:shaded:1.07:provided
[INFO] | | | | \- org.ow2.asm:asm:jar:4.0:provided
[INFO] | | | +- com.esotericsoftware.minlog:minlog:jar:1.2:provided
[INFO] | | | \- org.objenesis:objenesis:jar:1.2:provided
[INFO] | | +- org.yaml:snakeyaml:jar:1.11:provided
[INFO] | | +- org.apache.httpcomponents:httpclient:jar:4.1.1:provided
[INFO] | | | \- org.apache.httpcomponents:httpcore:jar:4.1:provided
[INFO] | | +- storm:tools.cli:jar:0.2.2:provided
[INFO] | | +- com.googlecode.disruptor:disruptor:jar:2.10.1:provided
[INFO] | | +- storm:jgrapht:jar:0.8.3:provided
[INFO] | | +- com.google.guava:guava:jar:13.0:provided
[INFO] | | \- ch.qos.logback:logback-classic:jar:1.0.6:provided
[INFO] | | \- ch.qos.logback:logback-core:jar:1.0.6:provided
[INFO] | \- storm:storm-netty:jar:0.9.0.1:provided
[INFO] | \- io.netty:netty:jar:3.6.3.Final:provided
[INFO] +- com.rabbitmq:amqp-client:jar:3.2.2:compile
[INFO] +- org.mongodb:mongo-java-driver:jar:2.11.3:compile
[INFO] +- org.springframework.data:spring-data-mongodb:jar:1.3.3.RELEASE:compile
[INFO] | +- org.springframework:spring-tx:jar:3.1.4.RELEASE:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | +- org.springframework:spring-beans:jar:3.1.4.RELEASE:compile
[INFO] | +- org.springframework:spring-expression:jar:3.1.4.RELEASE:compile
[INFO] | \- org.springframework.data:spring-data-commons:jar:1.6.3.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:3.2.3.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:3.2.3.RELEASE:compile
[INFO] | \- org.springframework:spring-aop:jar:3.2.3.RELEASE:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.6:compile
[INFO] +- org.slf4j:log4j-over-slf4j:jar:1.7.6:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.6:compile
[INFO] +- org.mockito:mockito-all:jar:1.9.0:test
[INFO] +- org.easytesting:fest-assert-core:jar:2.0M8:test
[INFO] | \- org.easytesting:fest-util:jar:1.2.3:test
[INFO] +- com.google.code.gson:gson:jar:2.2.4:compile
[INFO] \- commons-codec:commons-codec:jar:1.8:compile
编辑1:删除log4j依赖树之后
+- junit:junit:jar:4.8.1:test
[INFO] +- storm:storm:jar:0.9.0.1:provided
[INFO] | +- storm:storm-console-logging:jar:0.9.0.1:provided
[INFO] | +- storm:storm-core:jar:0.9.0.1:provided
[INFO] | | +- org.clojure:clojure:jar:1.4.0:provided
[INFO] | | +- commons-io:commons-io:jar:1.4:provided
[INFO] | | +- org.apache.commons:commons-exec:jar:1.1:provided
[INFO] | | +- storm:libthrift7:jar:0.7.0-2:provided
[INFO] | | | +- commons-lang:commons-lang:jar:2.5:provided
[INFO] | | | \- javax.servlet:servlet-api:jar:2.5:provided
[INFO] | | +- clj-time:clj-time:jar:0.4.1:provided
[INFO] | | | \- joda-time:joda-time:jar:2.0:provided
[INFO] | | +- com.netflix.curator:curator-framework:jar:1.0.1:provided
[INFO] | | | +- com.netflix.curator:curator-client:jar:1.0.1:provided
[INFO] | | | \- org.apache.zookeeper:zookeeper:jar:3.3.3:provided
[INFO] | | | \- jline:jline:jar:0.9.94:provided
[INFO] | | +- backtype:jzmq:jar:2.1.0:provided
[INFO] | | +- com.googlecode.json-simple:json-simple:jar:1.1:provided
[INFO] | | +- compojure:compojure:jar:1.1.3:provided
[INFO] | | | +- org.clojure:core.incubator:jar:0.1.0:provided
[INFO] | | | +- org.clojure:tools.macro:jar:0.1.0:provided
[INFO] | | | +- clout:clout:jar:1.0.1:provided
[INFO] | | | \- ring:ring-core:jar:1.1.5:provided
[INFO] | | | \- commons-fileupload:commons-fileupload:jar:1.2.1:provided
[INFO] | | +- hiccup:hiccup:jar:0.3.6:provided
[INFO] | | +- ring:ring-devel:jar:0.3.11:provided
[INFO] | | | \- clj-stacktrace:clj-stacktrace:jar:0.2.2:provided
[INFO] | | +- ring:ring-jetty-adapter:jar:0.3.11:provided
[INFO] | | | +- ring:ring-servlet:jar:0.3.11:provided
[INFO] | | | +- org.mortbay.jetty:jetty:jar:6.1.26:provided
[INFO] | | | | \- org.mortbay.jetty:servlet-api:jar:2.5-20081211:provided
[INFO] | | | \- org.mortbay.jetty:jetty-util:jar:6.1.26:provided
[INFO] | | +- org.clojure:tools.logging:jar:0.2.3:provided
[INFO] | | +- org.clojure:math.numeric-tower:jar:0.0.1:provided
[INFO] | | +- storm:carbonite:jar:1.5.0:provided
[INFO] | | | \- com.esotericsoftware.kryo:kryo:jar:2.17:provided
[INFO] | | | +- com.esotericsoftware.reflectasm:reflectasm:jar:shaded:1.07:provided
[INFO] | | | | \- org.ow2.asm:asm:jar:4.0:provided
[INFO] | | | +- com.esotericsoftware.minlog:minlog:jar:1.2:provided
[INFO] | | | \- org.objenesis:objenesis:jar:1.2:provided
[INFO] | | +- org.yaml:snakeyaml:jar:1.11:provided
[INFO] | | +- org.apache.httpcomponents:httpclient:jar:4.1.1:provided
[INFO] | | | \- org.apache.httpcomponents:httpcore:jar:4.1:provided
[INFO] | | +- storm:tools.cli:jar:0.2.2:provided
[INFO] | | +- com.googlecode.disruptor:disruptor:jar:2.10.1:provided
[INFO] | | +- storm:jgrapht:jar:0.8.3:provided
[INFO] | | +- com.google.guava:guava:jar:13.0:provided
[INFO] | | +- ch.qos.logback:logback-classic:jar:1.0.6:provided
[INFO] | | | \- ch.qos.logback:logback-core:jar:1.0.6:provided
[INFO] | | \- org.slf4j:log4j-over-slf4j:jar:1.6.6:provided
[INFO] | \- storm:storm-netty:jar:0.9.0.1:provided
[INFO] | \- io.netty:netty:jar:3.6.3.Final:provided
[INFO] +- com.rabbitmq:amqp-client:jar:3.2.2:compile
[INFO] +- org.mongodb:mongo-java-driver:jar:2.11.3:compile
[INFO] +- org.springframework.data:spring-data-mongodb:jar:1.3.3.RELEASE:compile
[INFO] | +- org.springframework:spring-tx:jar:3.1.4.RELEASE:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | +- org.springframework:spring-beans:jar:3.1.4.RELEASE:compile
[INFO] | +- org.springframework:spring-expression:jar:3.1.4.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-commons:jar:1.6.3.RELEASE:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.1:compile
[INFO] | \- org.slf4j:jcl-over-slf4j:jar:1.7.1:runtime
[INFO] +- org.springframework:spring-core:jar:3.2.3.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:3.2.3.RELEASE:compile
[INFO] | \- org.springframework:spring-aop:jar:3.2.3.RELEASE:compile
[INFO] +- org.mockito:mockito-all:jar:1.9.0:test
[INFO] +- org.easytesting:fest-assert-core:jar:2.0M8:test
[INFO] | \- org.easytesting:fest-util:jar:1.2.3:test
[INFO] +- com.google.code.gson:gson:jar:2.2.4:compile
[INFO] \- commons-codec:commons-codec:jar:1.8:compile
和pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.2.3.RELEASE</spring.version>
</properties>
<repositories>
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<!-- Storm library -->
<dependency>
<groupId>storm</groupId>
<artifactId>storm</artifactId>
<version>0.9.0.1</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- RabbitMQ Driver -->
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>3.2.2</version>
</dependency>
<!-- mongodb java driver -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.11.3</version>
</dependency>
<!-- Spring data mongodb -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.3.3.RELEASE</version>
</dependency>
<!-- Spring framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Log4j -->
<!-- Unit Testing Tools -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert-core</artifactId>
<version>2.0M8</version>
<scope>test</scope>
</dependency>
<!-- dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId>
<version>6.8</version> <scope>test</scope> </dependency> -->
<!-- Google JSON serialization -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<!-- Encoder -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build.profile.id>local</build.profile.id>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<build.profile.id>dev</build.profile.id>
</properties>
</profile>
<profile>
<id>stage</id>
<properties>
<build.profile.id>stage</build.profile.id>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<build.profile.id>prod</build.profile.id>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>clean</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<delete file="src/main/resources/application.properties" />
<copy file="profiles/application.${build.profile.id}.properties"
tofile="src/main/resources/application.properties" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.madisonlogic.conscriptor.topology.ConscriptorTopology</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<!-- Used to Correct slf4j errors with log4j -->
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<searchTransitive>true</searchTransitive>
<excludes>
<exclude>commons-logging</exclude>
<exclude>org.slf4j:1.5*</exclude>
<exclude>org.slf4j:1.6*</exclude>
<exclude>org.springframework:2.*</exclude>
<exclude>org.springframework:3.0.*</exclude>
</excludes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
编辑2更新的pom.xml
<!-- Log4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
</exclusion>
</exclusions>
</dependency>
1条答案
按热度按时间cbeh67ev1#
发现了问题。它在/.classpath中。我将类路径文件与工作项目进行了比较,并删除了任何其他引用。而且成功了。
坏的类路径有很多特定于jar的引用,如下所示
下面左边是一个diffb/t坏类路径文件,右边是正确的类路径文件。
我不知道这些课程是怎么进来的。