Class 排除后路径包含多个 SLF4J 绑定

Class path contains multiple SLF4J bindings after exclusion

我在启动网络应用程序服务器时遇到错误 "Class path contains multiple SLF4J bindings."。我在这里找到的解决方案似乎没有用。我已经从域中排除了工件,但我仍然收到错误。我不明白为什么即使在排除之后我也会出现错误。我使用 Glassfish 4.1.1 作为服务器。

Severe: SLF4J: Class path contains multiple SLF4J bindings.
Severe: SLF4J: Found binding in [jar:file:/C:/glassfish4.1.1/glassfish/domains/domain1/eclipseApps/csbasement/WEB-INF/lib/slf4j-log4j12-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
Severe: SLF4J: Found binding in [jar:file:/C:/glassfish4.1.1/glassfish/domains/domain1/eclipseApps/csbasement/WEB-INF/lib/slf4j-simple-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
Severe: SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

我排除了在错误代码中提供的 link 中看到的工件:

    <!-- slf4j -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.12</version>
        <exclusions>
          <exclusion> 
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
          </exclusion>
        </exclusions> 
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.12</version>
        <exclusions>
          <exclusion> 
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
          </exclusion>
        </exclusions> 
    </dependency>

mvn:树:

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ maventest ---
[INFO] maventest:maventest:jar:0.0.1-SNAPSHOT
[INFO] +- org.omnifaces:omnifaces:jar:2.1:compile
[INFO] +- org.webjars:font-awesome:jar:4.4.0:compile
[INFO] +- org.ocpsoft.rewrite:rewrite-servlet:jar:2.0.12.Final:compile
[INFO] +- org.ocpsoft.rewrite:rewrite-config-prettyfaces:jar:2.0.12.Final:compile
[INFO] |  +- org.ocpsoft.rewrite:rewrite-annotations-impl:jar:2.0.12.Final:compile
[INFO] |  |  +- org.ocpsoft.rewrite:rewrite-api:jar:2.0.12.Final:compile
[INFO] |  |  |  +- org.ocpsoft.common:common-api:jar:1.0.5.Final:compile
[INFO] |  |  |  \- org.ocpsoft.logging:logging-api:jar:1.0.2.Final:compile
[INFO] |  |  +- org.ocpsoft.rewrite:rewrite-api-servlet:jar:2.0.12.Final:compile
[INFO] |  |  |  \- org.ocpsoft.rewrite:rewrite-addressbuilder:jar:2.0.12.Final:compile
[INFO] |  |  \- org.ocpsoft.rewrite:rewrite-annotations-api:jar:2.0.12.Final:compile
[INFO] |  \- org.ocpsoft.rewrite:rewrite-integration-faces:jar:2.0.12.Final:compile
[INFO] +- commons-io:commons-io:jar:2.4:compile
[INFO] +- org.primefaces:primefaces:jar:5.3:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.1:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.9:compile
[INFO] +- com.google.guava:guava:jar:18.0:compile
[INFO] +- org.twitter4j:twitter4j-core:jar:4.0.4:compile
[INFO] +- org.twitter4j:twitter4j-stream:jar:4.0.4:compile
[INFO] +- com.twitter:hbc-core:jar:2.2.0:compile
[INFO] |  +- com.twitter:joauth:jar:6.0.2:compile
[INFO] |  \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.7.12:compile
[INFO] +- org.jsoup:jsoup:jar:1.8.2:compile
[INFO] +- com.ocpsoft:ocpsoft-pretty-time:jar:1.0.7:compile
[INFO] +- jstl:jstl:jar:1.2:compile
[INFO] \- com.google.code.gson:gson:jar:2.3.1:compile

这是我的全部 pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>maventest</groupId>
  <artifactId>maventest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

    <dependencies>

        <!-- omnifaces -->
        <dependency>
            <groupId>org.omnifaces</groupId>
            <artifactId>omnifaces</artifactId>
            <version>2.1</version>
        </dependency>


        <!-- font awesome -->

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>font-awesome</artifactId>
            <version>4.4.0</version>
        </dependency>


        <dependency>
            <groupId>org.ocpsoft.rewrite</groupId>
            <artifactId>rewrite-servlet</artifactId>
            <version>2.0.12.Final</version>

        </dependency>
        <dependency>
            <groupId>org.ocpsoft.rewrite</groupId>
            <artifactId>rewrite-config-prettyfaces</artifactId>
            <version>2.0.12.Final</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>



        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.3</version>
        </dependency>


        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5</version>
        </dependency>

        <!-- twitter -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>18.0</version>
        </dependency>

        <dependency>
            <groupId>org.twitter4j</groupId>
            <artifactId>twitter4j-core</artifactId>
            <version>4.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.twitter4j</groupId>
            <artifactId>twitter4j-stream</artifactId>
            <version>4.0.4</version>
        </dependency>

        <dependency>
            <groupId>com.twitter</groupId>
            <artifactId>hbc-twitter4j</artifactId>
            <version>2.2.0</version>
        </dependency>

        <dependency>
            <groupId>com.twitter</groupId>
            <artifactId>hbc-core</artifactId> <!-- or hbc-twitter4j -->
            <version>2.2.0</version> <!-- or whatever the latest version is -->
        </dependency>

        <!-- slf4j -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.12</version>
            <exclusions>
              <exclusion> 
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
              </exclusion>
            </exclusions> 
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.12</version>
            <exclusions>
              <exclusion> 
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
              </exclusion>

您正在构建 .jar,通常如果 .jar 不是端点独立应用程序(即您通常从 java -jar myjar.jar 开始,而您正在添加它作为 war Web 应用程序的另一个依赖项),您不应包含 slf4j 实现。所以,只需删除 slf4j-simple 依赖项。