gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:50:31 25 4
gpt4 key购买 nike

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

我还在 IntelliJ 中打开了一个 Maven 项目,在 tomcat7 插件中选择“重新部署”选项后出现以下错误:

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.

在附加链接中,建议转到文件-> 项目结构-> Artifact 并检查错误。这是我看到的: 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>

你能帮我找出错误吗?

最佳答案

可能有两个问题:

  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: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/Maven-Repo/org/slf4j/slf4j-log4j12/1.5.6/slf4j-log4j12-1.5.6.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/D:/Maven-Repo/org/slf4j/slf4j-simple/1.7.21/slf4j-simple-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] SLF4J: The requested version 1.5.6 by your slf4j binding is not compatible with [1.6, 1.7] SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details. log4j:WARN No appenders could be found for logger (de.so.DemoSlf4j). log4j:WARN Please initialize the log4j system properly.

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

<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 No appenders could be found for logger (de.so.DemoSlf4j). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

那么这样做:

  • 如果有其他 Artifact 对日志记录框架(log4j、slf4f 等)具有级联依赖性,请查看您的项目依赖项。
  • 检查您的依赖项是否正确部署到您的 Tomcat。 (.../WEB-INF/lib)
  • 检查版本

关于maven - 无法加载类 “org.slf4j.impl.StaticLoggerBinder” 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39976339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com