java SLF4J:slf4j-api 1.6.x(或更高版本)与此绑定不兼容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32826250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 20:50:41  来源:igfitidea点击:

SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding

javajakarta-eeslf4j

提问by Zeus

2015-09-28 10:02:21,890 ERROR [STDERR] (HDScanner) SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.
2015-09-28 10:02:21,891 ERROR [STDERR] (HDScanner) SLF4J: Your binding is version 1.5.5 or earlier.
2015-09-28 10:02:21,891 ERROR [STDERR] (HDScanner) SLF4J: Upgrade your binding to version 1.6.x.
2015-09-28 10:02:21,891 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/metasolv-web]] (HDScanner) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;

How do I fix this error? Also, in my application, I do not use slf4j anywhere, only the Dozer library uses it. from the below stacktrace I see that the spring application is using the slf4j, but why does it not load one on its own?

我该如何解决这个错误?另外,在我的应用程序中,我没有在任何地方使用 slf4j,只有 Dozer 库使用它。从下面的堆栈跟踪中我看到 spring 应用程序正在使用 slf4j,但为什么它不自己加载一个?

java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:645)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:191)

采纳答案by Zeus

I had to excluded the slf4j depenedencies from the dozer library and add dependencies directly to the POM file.

我不得不从推土机库中排除 slf4j 依赖项,并将依赖项直接添加到 POM 文件中。

As mentioned by @Powerlord, i had to add two libraries, one for the core slf4j and the other one is a binding library.

正如@Powerlord 提到的,我不得不添加两个库,一个用于核心 slf4j,另一个是绑定库。

Maven dependencies below.

Maven 依赖项如下。

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

        <dependency>
            <groupId>net.sf.dozer</groupId>
            <artifactId>dozer</artifactId>
            <version>5.5.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>jcl-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>

回答by Dave G

SLF4J is statically bound based on dependency.

SLF4J 是基于依赖静态绑定的。

If you are using log4j, you should have the log4j binding in your application.

如果您使用的是 log4j,则您的应用程序中应该有 log4j 绑定。

Even if you are not using slf4j you will need to have a binding (simple or noop) to get it to load properly from a dependent library.

即使您不使用 slf4j,您也需要有一个绑定(simple 或 noop)才能从依赖库正确加载它。