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;
如何修复此错误?另外,在我的应用程序中,我不在任何地方使用slf4j,只有Dozer库使用它。从下面的stacktrace我看到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)
答案 0 :(得分:6)
我不得不从dozer库中排除slf4j依赖项,并将依赖项直接添加到POM文件中。
如@Powerlord所述,我必须添加两个库,一个用于核心slf4j,另一个是绑定库。
下面的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>
答案 1 :(得分:1)
SLF4J基于依赖性进行静态绑定。
如果您使用的是log4j,则应在应用程序中使用log4j绑定。
即使你没有使用slf4j,你也需要一个绑定(简单或noop)才能从依赖库中正确加载它。