无法加载类“org.slf4j.impl.StaticLoggerBinder”错误

问题描述 投票:3回答:3

我在帖子中找不到解决方案之后打开这篇文章:Failed to load class "org.slf4j.impl.StaticLoggerBinder" error

我还在IntelliJ中打开了一个Maven项目,并在tomcat7插件中选择'redeploy'选项后出现以下错误:

SLF4J:无法加载类“org.slf4j.impl.StaticLoggerBinder”。 SLF4J:默认为无操作(NOP)记录器实现SLF4J:有关更多详细信息,请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder

在附加的链接中,建议转到File-> Project Structure - > Artifacts并检查错误。这就是我所看到的:enter image description here

我在pom.xml文件中也有以下依赖项:

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.21</version>
        </dependency>

你能帮我找错吗?

maven tomcat intellij-idea log4j slf4j
3个回答
7
投票

也许有两个问题:

  1. 版本不匹配您的依赖项
  2. 部署应用程序时出现问题

为了重现你的错误,我创建了这个迷你程序:

package de.so;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DemoSlf4j
{
    private static Logger logger = LoggerFactory.getLogger(DemoSlf4j.class);

    public static void main(String[] args)
    {
        logger.error("Start ...");
    }
}

在pom.xml中只有这些依赖项(与您使用的相同):

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.6</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version>
    </dependency>
</dependencies>

我有这些消息:

SLF4J:类路径包含多个SLF4J绑定。 SLF4J:在[jar:file:/ D:/Maven-Repo/org/slf4j/slf4j-log4j12/1.5.6/slf4j-log4j12-1.5.6.jar!/org/slf4j/impl/StaticLoggerBinder.class中找到绑定] SLF4J:在[jar:file:/ D:/Maven-Repo/org/slf4j/slf4j-simple/1.7.21/slf4j-simple-1.7.21.jar!/ org / slf4j / impl / StaticLoggerBinder中找到绑定。课程] SLF4J:请参阅http://www.slf4j.org/codes.html#multiple_bindings以获得解释。 SLF4J:实际绑定的类型为[org.slf4j.impl.Log4jLoggerFactory] ​​SLF4J:slf4j绑定所请求的版本1.5.6与[1.6,1.7] SLF4J不兼容:有关详细信息,请参阅http://www.slf4j.org/codes.html#version_mismatch。 log4j:WARN没有为logger找到appender(de.so.DemoSlf4j)。 log4j:WARN请正确初始化log4j系统。

当我使用这些依赖项时,一切都很好。看看版本!

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.21</version> <!-- or use LATEST -->
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version> <!-- or use LATEST -->
    </dependency>
</dependencies>

如果您使用org.slf4j:slf4j-log4j12:1.7.21而不是slf4j-simple(更有可能用于生产目的),您将获得:

log4j:WARN没有为logger找到appender(de.so.DemoSlf4j)。 log4j:WARN请正确初始化log4j系统。 log4j:WARN有关详细信息,请参阅http://logging.apache.org/log4j/1.2/faq.html#noconfig

这样做:

  • 如果有其他工件与日志框架(log4j,slf4f,...)具有级联依赖关系,请查看项目依赖项。
  • 检查您的依赖项是否已正确部署到Tomcat。 (... / WEB-INF / lib目录)
  • 检查版本

0
投票

您提供了一个log api和两个不同的实现,slf4j-log4j12slf4j-simple。我有同样的问题,但在我的情况下,它给了我一个错误消息,要求我从类路径中“删除一个”。

您可以尝试从依赖项中删除slf4j-simpleslf4j-log4j12,再次清理和构建项目。


0
投票

也许你在你的项目中得到破解的jar,在调试模型细节中检查它,我也有这个问题,当我用调试模型构建时,我看到警告:

/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar,所以删除它,并再次构建它。问题解决了。

© www.soinside.com 2019 - 2024. All rights reserved.