位置说明书上的SLF4J NoSuchMethodError [英] SLF4J NoSuchMethodError on LocationAwareLogger

查看:195
本文介绍了位置说明书上的SLF4J NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是以前已经问过的一个问题,但不幸的是没有解决方案似乎适用于我。我正在面对这个异常(带有简短的堆栈跟踪):

  java.lang.NoSuchMethodError:org.slf4j.spi.LocationAwareLogger。 log(Lorg / slf4j / Marker; Ljava / lang / String; ILjava / lang / String; [Ljava / lang / Object; Ljava / lang / Throwable;)V 
在org.apache.commons.logging.impl。 SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133)
在org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager $ 1.getConnection(ThreadSafeClientConnManager.java:221)
在org.apache.http.impl .client.DefaultRequestDirector.execute(DefaultRequestDirector.java:401)
在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)

使用命令行Maven编译时,以及部署到Tomcat时也会发生这种情况。它在IntelliJ IDEA中工作正常。



通常我会期望这是由正在使用的SLF4J库的多个版本引起的。但Maven依赖树显示了单个版本中的所有slf4j库:

  .. $ mvn依赖关系:树| grep slf4j 
[INFO] + - org.slf4j:slf4j-simple:jar:1.6.4:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.6.4:compile
[INFO] + - org.slf4j:slf4j-api:jar:1.6.4:compile
[INFO] + - org.slf4j:jcl-over-slf4j:jar:1.6.4:compile
[INFO] + - org.slf4j:slf4j-simple:jar:1.6.4:compile

我甚至确保〜/ .m2 / repository中没有其他JAR



没有对commons-logging库的引用(我排除了所有这些都被依赖树确认。



我如何解决这个问题?出来的想法。



编辑:根据要求,完全依赖关系,首先是父POM:

 < dependencyManagement> 
< dependencies>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-validator< / artifactId>
< version> $ {org.hibernate.validator.version}< / version>
<排除>
<! - 排除SLF4j以避免版本冲突(我们有1.6.2,在1.6.1中拖动) - >
< exclude>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-api< / artifactId>
< / exclusion>
< / exclusions>
< / dependency>
<依赖关系>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-validator-annotation-processor< / artifactId>
< version> $ {org.hibernate.validator.version}< / version>
< / dependency>

<依赖关系>
< groupId> javax.validation< / groupId>
< artifactId> validation-api< / artifactId>
< version> 1.0.0.GA< / version>
< / dependency>
<依赖关系>
< groupId> org.springframework< / groupId>
< artifactId> spring-context< / artifactId>
< version> $ {org.springframework.version}< / version>
<排除>
<! - 排除Commons登录SLF4j - >
< exclude>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< / exclusion>
< / exclusions>
< / dependency>
<依赖关系>
< groupId> org.springframework< / groupId>
< artifactId> spring-webmvc< / artifactId>
< version> $ {org.springframework.version}< / version>
< / dependency>
<依赖关系>
< groupId> org.springframework.security< / groupId>
< artifactId> spring-security-config< / artifactId>
< version> $ {org.springframework.version}< / version>
< / dependency>
<依赖关系>
< groupId> org.springframework.security< / groupId>
< artifactId> spring-security-core< / artifactId>
< version> $ {org.springframework.version}< / version>
< / dependency>
<依赖关系>
< groupId> org.springframework.security< / groupId>
< artifactId> spring-security-web< / artifactId>
< version> $ {org.springframework.version}< / version>
< / dependency>
<依赖关系>
< groupId> org.springframework.security< / groupId>
< artifactId> spring-security-taglibs< / artifactId>
< version> $ {org.springframework.version}< / version>
< / dependency>
<依赖关系>
< groupId> javax.inject< / groupId>
< artifactId> javax.inject< / artifactId>
< version> 1< / version>
< / dependency>

< dependency>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.8.2< / version>
< / dependency>
<依赖关系>
< groupId> org.slf4j< / groupId>
< artifactId> $ {org.slf4j.backend}< / artifactId>
< version> $ {org.slf4j.version}< / version>
< / dependency>
<依赖关系>
< groupId> org.hsqldb< / groupId>
< artifactId> hsqldb< / artifactId>
< version> 2.2.4< / version>
< / dependency>
<依赖关系>
< groupId> org.apache.httpcomponents< / groupId>
< artifactId> httpclient< / artifactId>
< version> 4.1.2< / version>
< / dependency>
<依赖关系>
< groupId> joda-time< / groupId>
< artifactId> joda-time< / artifactId>
< version> 2.0< / version>
< / dependency>
<依赖关系>
< groupId> joda-time< / groupId>
< artifactId> joda-time-jsptags< / artifactId>
< version> 1.0.2< / version>
< / dependency>
<依赖关系>
< groupId> javax.servlet< / groupId>
< artifactId> servlet-api< / artifactId>
< version> 2.5< / version>
< / dependency>
<依赖关系>
< groupId> javax.servlet.jsp< / groupId>
& artifactId> jsp-api< / artifactId>
< version> 2.1< / version>
< / dependency>
<依赖关系>
< groupId> javax.servlet< / groupId>
< artifactId> jstl< / artifactId>
< version> 1.2< / version>
< / dependency>
<依赖关系>
< groupId> postgresql< / groupId>
< artifactId> postgresql< / artifactId>
< version> 9.0-801.jdbc4< / version>
< / dependency>
<依赖关系>
< groupId> org.apache.commons< / groupId>
< artifactId> commons-lang3< / artifactId>
< version> 3.0.1< / version>
< / dependency>
< / dependencies>
< / dependencyManagement>

然后失败的模块:

 <依赖性> 
//跳过客户端特定依赖项//

< dependency>
< groupId> com.google.guava< / groupId>
< artifactId> guava< / artifactId>
< version> 10.0.1< / version>
< / dependency>

<! - Spring - >
<依赖关系>
< groupId> org.springframework< / groupId>
< artifactId> spring-context< / artifactId>
<排除>
<! - 排除Commons登录SLF4j - >
< exclude>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< / exclusion>
< / exclusions>
< / dependency>
<依赖关系>
< groupId> org.springframework< / groupId>
< artifactId> spring-webmvc< / artifactId>
< / dependency>
<依赖关系>
< groupId> org.springframework.security< / groupId>
< artifactId> spring-security-config< / artifactId>
< scope>运行时< / scope>
< / dependency>
<依赖关系>
< groupId> org.springframework.security< / groupId>
< artifactId> spring-security-core< / artifactId>
< scope> compile< / scope>
< / dependency>
<依赖关系>
< groupId> org.springframework.security< / groupId>
< artifactId> spring-security-web< / artifactId>
< scope> compile< / scope>
< / dependency>
<依赖关系>
< groupId> org.springframework.security< / groupId>
< artifactId> spring-security-taglibs< / artifactId>
< scope>运行时< / scope>
< / dependency>
<依赖关系>
< groupId> javax.inject< / groupId>
< artifactId> javax.inject< / artifactId>
< / dependency>
<依赖关系>
< groupId> cglib< / groupId>
< artifactId> cglib< / artifactId>
< version> 2.2.2< / version>
< / dependency>

<! - 记录 - >
<依赖关系>
< groupId> net.sf.opencsv< / groupId>
< artifactId> opencsv< / artifactId>
< version> 2.0< / version>
< / dependency>
<依赖关系>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-api< / artifactId>
< version> $ {org.slf4j.version}< / version>
< / dependency>
<依赖关系>
< groupId> org.slf4j< / groupId>
< artifactId> jcl-over-slf4j< / artifactId>
< version> $ {org.slf4j.version}< / version>
< scope>运行时< / scope>
< / dependency>
<依赖关系>
< groupId> org.slf4j< / groupId>
< artifactId> $ {org.slf4j.backend}< / artifactId>
< version> $ {org.slf4j.version}< / version>
< scope>运行时< / scope>
< / dependency>
<依赖关系>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2.16< / version>
< / dependency>

<! - Joda时间 - >
<依赖关系>
< groupId> joda-time< / groupId>
< artifactId> joda-time< / artifactId>
< / dependency>
<依赖关系>
< groupId> joda-time< / groupId>
< artifactId> joda-time-jsptags< / artifactId>
< scope>运行时< / scope>
< / dependency>

<! - Servlet - >
<依赖关系>
< groupId> javax.servlet< / groupId>
< artifactId> servlet-api< / artifactId>
< scope>已提供< / scope>
< / dependency>
<依赖关系>
< groupId> javax.servlet.jsp< / groupId>
< artifactId> jsp-api< / artifactId>
< scope>已提供< / scope>
< / dependency>
<依赖关系>
< groupId> javax.servlet< / groupId>
< artifactId> jstl< / artifactId>
< / dependency>
<依赖关系>
< groupId> com.google.visualization< / groupId>
< artifactId> visualization-datasource< / artifactId>
< version> 1.0.2< / version>
< / dependency>

<依赖关系>
< groupId> org.mybatis< / groupId>
< artifactId> mybatis-spring< / artifactId>
< version> 1.0.2< / version>
< / dependency>
<依赖关系>
< groupId> commons-dbcp< / groupId>
< artifactId> commons-dbcp< / artifactId>
< version> 1.4< / version>
< / dependency>
<依赖关系>
< groupId> org.codehaus.jackson< / groupId>
< artifactId> jackson-mapper-asl< / artifactId>
< version> 1.9.0< / version>
< / dependency>
<依赖关系>
< groupId> commons-io< / groupId>
< artifactId> commons-io< / artifactId>
< version> 2.1< / version>
< / dependency>
<依赖关系>
< groupId> commons-fileupload< / groupId>
< artifactId> commons-fileupload< / artifactId>
< version> 1.2.2< / version>
< / dependency>

<依赖关系>
< groupId> org.apache.poi< / groupId>
< artifactId> poi< / artifactId>
< version> 3.7< / version>
< / dependency>
<依赖关系>
< groupId> org.apache.poi< / groupId>
< artifactId> poi-ooxml< / artifactId>
< version> 3.7< / version>
< / dependency>
<依赖关系>
< groupId> org.apache.poi< / groupId>
< artifactId> poi-ooxml-schemas< / artifactId>
< version> 3.7< / version>
< / dependency>

<依赖关系>
< groupId> postgresql< / groupId>
< artifactId> postgresql< / artifactId>
< scope>运行时< / scope>
< / dependency>

<依赖关系>
< scope> test< / scope>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< / dependency>
< / dependencies>

这些是父母设置的属性:

 <性状> 
< project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding>
< org.hibernate.validator.version> 4.2.0.Final< /org.hibernate.validator.version>
< org.slf4j.backend> slf4j-simple< /org.slf4j.backend>
< org.slf4j.version> 1.6.4< /org.slf4j.version>
< org.springframework.version> 3.0.5.RELEASE< /org.springframework.version>
< / properties>

尽管我最近的实验似乎并不是一个与项目文件有关的问题。我试图'hg平分'的问题,但回到几周我找不到一个版本的作品。其中一些在生产系统中运行,因此不太可能是导致此问题的代码更改。

解决方案

NoSuchMethodError的javadocs说,


通常,这个错误被编译器捕获;

$ p

这个错误可能只在运行时发生,如果一个类的定义已经不相符。由加载的slf4j的不兼容版本引起的。而不是查看你的类路径并猜测哪些类被加​​载,可以按照此处



打印出 org.slf4j.spi.LocationAwareLogger org.apache.commons .logging.impl.SLF4JLocationAwareLog org.slf4j.Marker 正在加载。


This is a question that has been asked before, but unfortunately no solution seems to work for me. I am facing this exception (with abridged stack trace):

java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
    at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133)
    at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager$1.getConnection(ThreadSafeClientConnManager.java:221)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:401)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)

This happens when compiling using a command line Maven and also when deploying to Tomcat. It works fine inside IntelliJ IDEA.

Usually I would expect this to be caused by multiple versions of the SLF4J library being in use. But the Maven dependency tree shows all slf4j libraries in a single version:

..$ mvn dependency:tree | grep slf4j
[INFO] +- org.slf4j:slf4j-simple:jar:1.6.4:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.6.4:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.6.4:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.6.4:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.6.4:compile

I even ensured that there is no other JAR in ~/.m2/repository

There are no references to commons-logging libraries either (I excluded them all as confirmed by the dependency tree.

How can I resolve this issue? I'm running out of ideas.

EDIT: as requested here the full dependencies, first the parent POM:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${org.hibernate.validator.version}</version>
            <exclusions>
                <!-- Exclude SLF4j to avoid version conflicts (we have 1.6.2, this drags in 1.6.1) -->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator-annotation-processor</artifactId>
            <version>${org.hibernate.validator.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework.version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>${org.slf4j.backend}</artifactId>
            <version>${org.slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.1.2</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time-jsptags</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.0-801.jdbc4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0.1</version>
        </dependency>
    </dependencies>
</dependencyManagement>

And then the module that fails:

<dependencies>
    // client specific dependencies skipped //

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>10.0.1</version>
    </dependency>

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <exclusions>
            <!-- Exclude Commons Logging in favor of SLF4j -->
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>

    <!-- Logging -->
    <dependency>
        <groupId>net.sf.opencsv</groupId>
        <artifactId>opencsv</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${org.slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>${org.slf4j.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>${org.slf4j.backend}</artifactId>
        <version>${org.slf4j.version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>

    <!-- Joda Time -->
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time-jsptags</artifactId>
        <scope>runtime</scope>
    </dependency>

    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.visualization</groupId>
        <artifactId>visualization-datasource</artifactId>
        <version>1.0.2</version>
    </dependency>

    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>1.0.2</version>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.0</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.1</version>
    </dependency>
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>3.7</version>
    </dependency>

    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <scope>test</scope>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
</dependencies>

These are the properties set on the parent:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <org.hibernate.validator.version>4.2.0.Final</org.hibernate.validator.version>
    <org.slf4j.backend>slf4j-simple</org.slf4j.backend>
    <org.slf4j.version>1.6.4</org.slf4j.version>
    <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
</properties>

Given my recent experiments it doesn't seem to be an issue relating to the project files, though. I tried to 'hg bisect' the problem, but going back weeks I could not find a version that works. Some of these are running in production systems, so it is not likely to be a code change that causes this problem.

解决方案

The javadocs for NoSuchMethodError say,

Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.

So this is probably being caused by incompatible versions of slf4j being loaded. Rather than looking at your classpath and guessing where classes are loaded, find where your class is loaded as described here.

Print out where org.slf4j.spi.LocationAwareLogger, org.apache.commons.logging.impl.SLF4JLocationAwareLog and org.slf4j.Marker are being loaded from.

这篇关于位置说明书上的SLF4J NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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