SLF4J:未能装入类“org. SLF4J . request . staticloggerbinder”。在Maven项目中[复制]

时间:2021-08-24 11:47:53

This question already has an answer here:

这个问题已经有了答案:

I have a dependency for SLF4J. I am getting this error:

我对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.

Here is my maven entry:

这是我的maven条目:

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

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.6</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>

Where is the problem?

问题在哪里?


EDIT: Without log4j dependency I get the following exception

编辑:没有log4j依赖项,我得到以下异常。

Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: org.slf4j.impl.StaticLoggerBinder
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)
    at org.apache.bval.jsr303.ConfigurationImpl.<clinit>(ConfigurationImpl.java:50)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:228)
    at org.apache.bval.jsr303.ApacheValidationProvider.createGenericConfiguration(ApacheValidationProvider.java:66)
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:173)
    at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:50)
    at com.daimler.zv9.basic.entity.AbstractEntity.<clinit>(AbstractEntity.java:73)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:228)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:195)
    at java.lang.Class.forNameImpl(Native Method)
    at java.lang.Class.forName(Class.java:168)

EDIT2: It is an example MAVEN Tree that I get

EDIT2:这是我得到的一个MAVEN树示例。

[INFO] com.myCompany.abc:ABC_Document:ejb:0.0.1-SNAPSHOT
[INFO] +- com.myCompany.abc:ABC_Basic:jar:0.0.1-SNAPSHOT:compile
[INFO] +- com.myCompany.iap:javax.j2ee:jar:5.0.0:provided
[INFO] +- com.myCompany.iap:logging:jar:5.0.0:provided
[INFO] +- com.myCompany.iap:util:jar:5.0.0:provided
[INFO] +- junit:junit:jar:4.8.2:test
[INFO] +- javax.servlet:jstl:jar:1.2:provided
[INFO] +- org.slf4j:slf4j-api:jar:1.6.6:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.6.6:compile
[INFO] \- org.mockito:mockito-all:jar:1.9.0:test

4 个解决方案

#1


33  

I am assuming you are using Eclipse as your developing environment.

我假设您正在使用Eclipse作为开发环境。

Eclipse Juno, Indigo and Kepler when using the bundled maven version(m2e), are not suppressing the message SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". This behaviour is present from the m2e version 1.1.0.20120530-0009 and onwards.

在使用绑定的maven版本(m2e)时,Eclipse Juno、Indigo和Kepler并没有抑制消息SLF4J:未能装入类“org.slf4j.impl.StaticLoggerBinder”。这种行为来自于m2e版本1.1.0.20120530-0009和以后。

Although, this is indicated as an error your logs will be saved normally. The highlighted error will still be present until there is a fix of this bug. More about this in the m2e support site.

虽然,这是一个错误,您的日志将被正常保存。突出显示的错误将仍然存在,直到有了这个bug的修复。更多关于这个在m2e支持网站。

The current available solution is to use an external maven version rather than the bundled version of Eclipse. You can find about this solution and more details regarding this bug in the question below which i believe describes the same problem you are facing.

当前可用的解决方案是使用外部maven版本,而不是Eclipse的捆绑版本。您可以在下面的问题中找到关于这个问题的解决方案和更多的细节,我相信您所面对的问题是相同的。

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

SLF4J:未能装入类“org. SLF4J . request . staticloggerbinder”。错误

#2


16  

Remove

删除

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.16</version>
</dependency> 

slf4j-log4j12 is the log4j binding for slf4j you dont need to add another log4j dependency.

slf4j-log4j12是slf4j的log4j绑定,您不需要添加另一个log4j依赖项。

Added
Provide the log4j configuration in log4j.properties and add it to your class path. There are sample configurations here

在log4j中添加了log4j配置。属性并将其添加到类路径中。这里有一些样本配置。

or you can change your binding to

或者你可以改变你的绑定。

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.6.1</version>
</dependency>

if you are configuring slf4j due to some dependencies requiring it.

如果您正在配置slf4j,这是因为需要它的一些依赖项。

#3


8  

I ran into this in IntelliJ and fixed it by adding the following to my pom:

我在IntelliJ中遇到了这个问题,并通过在我的pom中添加以下内容来修复它:

<!-- logging dependencies -->
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>${logback.version}</version>
        <exclusions>
            <exclusion>
                <!-- Defined below -->
                <artifactId>slf4j-api</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
    </dependency>

#4


2  

The message you mention is quite clear:

你提到的信息很清楚:

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.

SLF4J API could not find a binding, and decided to default to a NOP implementation. In your case slf4j-log4j12.jar was somehow not visible when the LoggerFactory class was loaded into memory, which is admittedly very strange. What does "mvn dependency:tree" tell you?

SLF4J API无法找到绑定,并决定默认为NOP实现。在你的情况中slf4j-log4j12。当LoggerFactory类加载到内存中时,jar是不可见的,这是非常奇怪的。“mvn依赖:树”告诉你什么?

The various dependency declarations may not even be directly at cause here. I strongly suspect that a pre-1.6 version of slf4j-api.jar is being deployed without your knowledge.

在这里,各种依赖项声明甚至可能都不是直接的。我强烈怀疑1.6版的slf4j-api。jar在没有你的知识的情况下被部署。

#1


33  

I am assuming you are using Eclipse as your developing environment.

我假设您正在使用Eclipse作为开发环境。

Eclipse Juno, Indigo and Kepler when using the bundled maven version(m2e), are not suppressing the message SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". This behaviour is present from the m2e version 1.1.0.20120530-0009 and onwards.

在使用绑定的maven版本(m2e)时,Eclipse Juno、Indigo和Kepler并没有抑制消息SLF4J:未能装入类“org.slf4j.impl.StaticLoggerBinder”。这种行为来自于m2e版本1.1.0.20120530-0009和以后。

Although, this is indicated as an error your logs will be saved normally. The highlighted error will still be present until there is a fix of this bug. More about this in the m2e support site.

虽然,这是一个错误,您的日志将被正常保存。突出显示的错误将仍然存在,直到有了这个bug的修复。更多关于这个在m2e支持网站。

The current available solution is to use an external maven version rather than the bundled version of Eclipse. You can find about this solution and more details regarding this bug in the question below which i believe describes the same problem you are facing.

当前可用的解决方案是使用外部maven版本,而不是Eclipse的捆绑版本。您可以在下面的问题中找到关于这个问题的解决方案和更多的细节,我相信您所面对的问题是相同的。

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

SLF4J:未能装入类“org. SLF4J . request . staticloggerbinder”。错误

#2


16  

Remove

删除

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.16</version>
</dependency> 

slf4j-log4j12 is the log4j binding for slf4j you dont need to add another log4j dependency.

slf4j-log4j12是slf4j的log4j绑定,您不需要添加另一个log4j依赖项。

Added
Provide the log4j configuration in log4j.properties and add it to your class path. There are sample configurations here

在log4j中添加了log4j配置。属性并将其添加到类路径中。这里有一些样本配置。

or you can change your binding to

或者你可以改变你的绑定。

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.6.1</version>
</dependency>

if you are configuring slf4j due to some dependencies requiring it.

如果您正在配置slf4j,这是因为需要它的一些依赖项。

#3


8  

I ran into this in IntelliJ and fixed it by adding the following to my pom:

我在IntelliJ中遇到了这个问题,并通过在我的pom中添加以下内容来修复它:

<!-- logging dependencies -->
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>${logback.version}</version>
        <exclusions>
            <exclusion>
                <!-- Defined below -->
                <artifactId>slf4j-api</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
    </dependency>

#4


2  

The message you mention is quite clear:

你提到的信息很清楚:

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.

SLF4J API could not find a binding, and decided to default to a NOP implementation. In your case slf4j-log4j12.jar was somehow not visible when the LoggerFactory class was loaded into memory, which is admittedly very strange. What does "mvn dependency:tree" tell you?

SLF4J API无法找到绑定,并决定默认为NOP实现。在你的情况中slf4j-log4j12。当LoggerFactory类加载到内存中时,jar是不可见的,这是非常奇怪的。“mvn依赖:树”告诉你什么?

The various dependency declarations may not even be directly at cause here. I strongly suspect that a pre-1.6 version of slf4j-api.jar is being deployed without your knowledge.

在这里,各种依赖项声明甚至可能都不是直接的。我强烈怀疑1.6版的slf4j-api。jar在没有你的知识的情况下被部署。