NoSuchMethodError:org.slf4j.impl.StaticLoggerBinder.getSingleton() [英] NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()

查看:207
本文介绍了NoSuchMethodError:org.slf4j.impl.StaticLoggerBinder.getSingleton()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是由我的pom.xml [cxf-bundle-jaxrs]中的一个依赖项引起的,它在内部使用较低版本的slf4j。我设法通过将此依赖项升级到最新版本来解决此问题。谢谢大家。

The issue was caused by one of the dependencies in my pom.xml [cxf-bundle-jaxrs] which internally uses lower version of slf4j. I managed to resolve this issue by upgrading this dependency to the latest release. Thanks everyone.

我正在尝试将Apache Shiro添加到我的CXF Spring Web应用程序中。当我启动我的tomcat 7时出现以下错误

I'm trying to add Apache Shiro to my CXF Spring web application. When I start up my tomcat 7 I get the following error

Caused by: java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/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.shiro.spring.LifecycleBeanPostProcessor.<clinit>(LifecycleBeanPostProcessor.java:51)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)
... 25 more

我的shiro和slf4j的pom.xml是

and my pom.xml for shiro and slf4j is

<dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-core</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-web</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-spring</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <scope>runtime</scope>
    </dependency>

我已经通过谷歌搜索尝试了所有可能的解决方案,但没有运气。

I have tried every possible solution by googling, but no luck.

推荐答案

Caused by: java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;

这意味着您拥有类 StaticLoggerBinder 在你的类路径中。
但是你的类路径的类没有方法 getSingleton()

This means that you have the class StaticLoggerBinder in your classpath. But the class of your classpath does not have the method getSingleton()

这通常发生在你有依赖关系,它们都使用相同的传递依赖。这意味着您的2个依赖项(或您的应用程序和传递依赖项)都在内部使用不同版本的SLF4J。但是你的应用程序只能同时使用该类的单个版本,所以它必须选择(不知道这里的规则......随机吗?)

This usually happens when you have dependencies that both use the same transitive dependency. This means that 2 of your dependencies (or your app, and a transitive dependency) are both using SLF4J internally with different versions. But your app can only use a single version of the class at the same time so it has to choose (don't know the rules here... random?)

要解决这个问题,你通常需要做一个 mvn依赖:tree 来查看哪些使用不同版本的SLF4J。

To solve the problem, you usually need to do a mvn dependency:tree to see which are using different versions of SLF4J.

解决方案通常是在最低版本上使用maven依赖项排除。像SLF4J这样的库往往是反向兼容的,这意味着新版本不断添加更多功能。有时,一个方法被删除,然后你必须保留旧库版本,并祈祷。如果这不起作用,仍有一些选项,例如 JarJar

The solution is often to use a maven dependency exclusion on the lowest version. Libraries like SLF4J tend to be retrocompatible which means newer versions keep adding more features. Sometimes, a method is removed and then you have to keep the old library version, and pray. If this doesn't work there are still some options, like JarJar

但是对于日志库而言,它有时会有所不同,所以我的解释是出于一般目的,但很可能你没有使用正确的日志库依赖项,因为它们有非常特殊的包装,并不总是很容易理解:)

But for logging libraries it's sometimes a bit different, so my explaination is for general purpose, but it's probable you do not use the right logging library dependencies because they have very special packagings which are not always easy to understand :)

检查我找到的是什么:

  • https://github.com/qos-ch/slf4j/blob/SLF4J_1.5.5/slf4j-api/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
  • https://github.com/qos-ch/slf4j/blob/SLF4J_1.5.6/slf4j-api/src/main/java/org/slf4j/impl/StaticLoggerBinder.java

getSingleton()方法出现在1.5.6版本,所以你很可能有一个使用早于1.5.6的SLF4J版本的库:)你只需要用maven排除(并祈祷)排除它。

The getSingleton() method appeared at version 1.5.6, so it is very probable that you have a library that uses an SLF4J version older that 1.5.6 :) You just need to exclude it with a maven exclusion (and pray).

编辑:你应该尝试:

<dependency>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-bundle-jaxrs</artifactId>
  <version>2.2</version>
  <exclusions>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-jdk14</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </exclusion>
  </exclusions> 
</dependency>

更好的是,如果你有一个带有父pom的多模块maven项目,你可以将它与maven dependencyManagement xml一起使用节点。

Better, if you have a multimodule maven project with a parent pom you can use this with maven dependencyManagement xml node.

这篇关于NoSuchMethodError:org.slf4j.impl.StaticLoggerBinder.getSingleton()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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