【问题标题】:SLF4J Binding ErrorSLF4J 绑定错误
【发布时间】:2012-07-06 01:34:49
【问题描述】:

我是 maven 的新手,最近两天我尝试将 maven 集成到一个小型 Web 项目中。 (我使用 Eclipse Juno 作为 IDE)。 首先,我使用“mvn-archetype-webapp”命令生成了一个新项目(结构),并将项目中的源代码复制到这个结构中。 然后我将所有依赖项添加到 pom.xml 中,以便我可以使用 tomcat7 插件编译和启动项目。 到目前为止,除了每个 maven 命令开头的 SLF4J 错误消息外,一切正常:

    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 
    SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J:
    See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

我的 pom.xml 依赖项如下所示:

    <!-- properties -->
    <properties>
        <spring.version>3.1.1.RELEASE</spring.version>
    </properties>

    <!-- dependencies -->   
    <dependencies>

        <!-- logging -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.6</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.6</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.6.6</version>
            <scope>runtime</scope>
        </dependency>

        <!-- junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <!-- Spring 3 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>   
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>                       
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>               
        </dependency>

        <!-- jee -->
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- tiles -->
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-core</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-api</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-jsp</artifactId>
            <version>2.2.2</version>
        </dependency>

        <!-- jstl -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>

有人可以帮我解决这个问题吗?

【问题讨论】:

标签: maven m2eclipse slf4j


【解决方案1】:

Eclipse Juno 和 Indigo 在使用捆绑的 maven 版本 (m2e) 时,不会抑制消息 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"。此行为从 m2e 版本 1.1.0.20120530-0009 及更高版本开始存在。

虽然,这表示为错误,您的日志将正常保存。在修复此错误之前,突出显示的错误仍将存在。更多信息请关注m2e support site

当前可用的解决方案是使用外部 maven 版本而不是 Eclipse 的捆绑版本。您可以在下面的问题中找到有关此解决方案以及有关此错误的更多详细信息,这与您面临的问题完全相同。

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". error

【讨论】:

    【解决方案2】:

    此错误来自运行 maven 的 eclipse,而不是来自您的项目,因此它不会影响您的构建过程或生成的文件。

    我认为这是与使用 slf4j 或其他日志工具的 maven 相关的问题,但 eclipse 或 maven 插件尝试这样做。

    消除错误的最简单方法是使用外部 maven 而不是 eclipse 中的运行时,您可以在 Preferences -> Maven -> Installations 中进行配置。

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题:我已将我的 POM 复制到一个空项目中,并将其缩减到几乎没有(见下文)——我仍然看到错误。我可以通过将 SLF4J 绑定(logback 等)添加到 POM 来验证它不会消失——消息显然来自 Maven 本身,而不是正在编译和测试的项目软件。 (我现在从一个完全空的项目中得到它。)

      我能想到的最好的事情是,我认为它与 Eclipse 有关:当我从命令行手动运行 Maven 时,不会出现错误——只有在 Eclipse 下调用时才会出现错误。 (我在 MacOSX 上使用 Eclipse Helios Release 2,仅供参考,所以我们知道问题不仅限于您的版本,Juno。)

      <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>testing</groupId>
        <artifactId>testing</artifactId>
        <version>0.0.1-SNAPSHOT</version>
      
      </project>
      

      仅供参考,响应 Ceki 的建议,这里是 maven 的依赖树目标的结果:

      SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
      SLF4J: Defaulting to no-operation (NOP) logger implementation
      SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
      [INFO] Scanning for projects...
      [INFO]                                                                         
      [INFO] ------------------------------------------------------------------------
      [INFO] Building testing 0.0.1-SNAPSHOT
      [INFO] ------------------------------------------------------------------------
      [INFO] 
      [INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ testing ---
      [INFO] testing:testing:jar:0.0.1-SNAPSHOT
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD SUCCESS
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 1.496s
      [INFO] Finished at: Thu Oct 04 10:05:41 MDT 2012
      [INFO] Final Memory: 9M/81M
      [INFO] ------------------------------------------------------------------------
      

      信息量不大,但确实有。

      【讨论】:

        【解决方案4】:

        依赖声明看起来不错。 Logback 和 slf4j 将在您的网络应用程序中发布。但是,我怀疑 slf4j-api.jar 以某种方式包含在 Tomcat 中(但不是 logback)。

        顺便说一句,mvn dependency:tree 命令是你的朋友。它说什么?

        【讨论】:

        • 在上面的答案中添加了 Maven 依赖项。 (是的,几个月后仍在发生......)
        【解决方案5】:

        尝试添加 logback-core 的依赖项。

            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-core</artifactId>
                <version>1.0.6</version>
                <scope>runtime</scope>
            </dependency>
        

        【讨论】:

        • 声明 logback-classic 足以通过 Maven 依赖传递性引入 logback-core 和 slf4j-api。无需将 logback-core 声明为依赖项。
        【解决方案6】:

        “使用tomcat7插件”

        tomcat7 插件具有 SLF4J 依赖项。在我将依赖项 direct 分配给 tomcat7 插件之前,我遇到了同样的问题。

        <pluginManagement>
        <plugins>
           <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <dependencies>
                    <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-simple</artifactId>
                        <version>1.7.5</version>
                    </dependency>                    
                </dependencies>
                <configuration>
                    <!-- ...snip... -->
                </configuration>
            </plugin>
        </plugins>
        </pluginManagement>
        

        【讨论】:

          【解决方案7】:

          您可以将其添加到您的 pom 属性中。

              <org.slf4j-version>1.7.5</org.slf4j-version>
          

          【讨论】:

            猜你喜欢
            • 2016-10-28
            • 1970-01-01
            • 2023-03-28
            • 1970-01-01
            • 2021-05-23
            • 2015-08-10
            • 2018-12-10
            • 2018-07-10
            相关资源
            最近更新 更多