SLF4J:无法加载类“org.slf4j.impl.StaticLoggerBinder”。在Maven项目中 [英] SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". in a Maven Project

查看:1843
本文介绍了SLF4J:无法加载类“org.slf4j.impl.StaticLoggerBinder”。在Maven项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SLF4J有依赖性。我收到此错误:

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

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.

这是我的maven条目:

Here is my maven entry:

    <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>

问题出在哪里?

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

Without log4j dependency I get the following exception

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 :这是我获得的MAVEN树的一个例​​子


EDIT2: It is an example MAVEN Tree that I get

[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


推荐答案

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

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

当使用捆绑的maven版本(m2e)时,Eclipse Juno,Indigo和Kepler不会抑制消息SLF4J:无法加载类org.slf4j.impl。 StaticLoggerBinder。此行为存在于m2e版本1.1.0.20120530-0009及之后。

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.

尽管如此,这表示您的日志会正常保存。在修复此错误之前,突出显示的错误仍将存在。有关此内容的更多信息,请参见 m2e支持网站

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.

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

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.

SLF4J:无法加载类org.slf4j.impl.StaticLoggerBinder。错误

这篇关于SLF4J:无法加载类“org.slf4j.impl.StaticLoggerBinder”。在Maven项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆