java.lang.NoSuchMethodError:org.slf4j.spi.LocationAwareLogger.log(Lorg / slf4j / Marker; Ljava / lang / String; ILjava / lang / String; Ljava / lang / Throwable;)V

时间:2018-06-17 22:00:55

标签: eclipse maven jar dependencies slf4j

我在Eclipse中使用Tomcat 8.5服务器运行项目时出现此错误:

SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
    at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:159)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:270)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4792)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5256)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1421)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1411)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

我在 pom.xml 中关于 slf4j 的依赖关系是:

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

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.25</version>
</dependency>

当我在项目中运行'mvn dependency:tree'时,结果是:

[INFO] Scanning for projects...
[WARNING] The POM for org.apache.tomcat.maven:tomcat8-maven-plugin:jar:3.0-r1756463 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for org.apache.tomcat.maven:tomcat8-maven-plugin:3.0-r1756463: Plugin org.apache.tomcat.maven:tomcat8-maven-plugin:3.0-r1756463 or one of its dependencies could not be resolved: Failure to find org.apache.tomcat.maven:tomcat8-maven-plugin:jar:3.0-r1756463 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
[INFO]
[INFO] -----------------< GestionPracticas:GestionPracticas >------------------
[INFO] Building GestionPracticas 0.0.1-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[WARNING] The POM for org.apache.tomcat.maven:tomcat8-maven-plugin:jar:3.0-r1756463 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for org.apache.tomcat.maven:tomcat8-maven-plugin:3.0-r1756463: Plugin org.apache.tomcat.maven:tomcat8-maven-plugin:3.0-r1756463 or one of its dependencies could not be resolved: Failure to find org.apache.tomcat.maven:tomcat8-maven-plugin:jar:3.0-r1756463 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
[WARNING] The POM for org.springframework:spring-jcl:jar:5.0.6.RELEASE is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ GestionPracticas ---
[INFO] GestionPracticas:GestionPracticas:war:0.0.1-SNAPSHOT
[INFO] +- org.springframework:spring-core:jar:5.0.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-jcl:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:5.0.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:5.0.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:5.0.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-jdbc:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-aspects:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework.data:spring-data-jpa:jar:2.0.7.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:2.0.7.RELEASE:compile
[INFO] |  \- org.aspectj:aspectjrt:jar:1.8.12:compile
[INFO] +- org.springframework.security:spring-security-web:jar:5.0.5.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-core:jar:5.0.5.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-config:jar:5.0.5.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-taglibs:jar:5.0.5.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-acl:jar:5.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:4.3.14.RELEASE:test
[INFO] +- org.apache.tiles:tiles-core:jar:2.2.2:compile
[INFO] |  +- org.apache.tiles:tiles-api:jar:2.2.2:compile
[INFO] |  +- commons-digester:commons-digester:jar:2.0:compile
[INFO] |  \- org.slf4j:jcl-over-slf4j:jar:1.5.8:compile
[INFO] +- org.apache.tiles:tiles-servlet:jar:2.2.2:compile
[INFO] +- org.apache.tiles:tiles-jsp:jar:2.2.2:compile
[INFO] |  \- org.apache.tiles:tiles-template:jar:2.2.2:compile
[INFO] +- mysql:mysql-connector-java:jar:6.0.6:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.3.0.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:4.3.0.Final:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.4.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] |  \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] +- org.hibernate:hibernate-validator:jar:4.3.1.Final:compile
[INFO] |  \- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] +- org.hibernate:hibernate-c3p0:jar:4.2.3.Final:compile
[INFO] |  \- com.mchange:c3p0:jar:0.9.2.1:compile
[INFO] |     \- com.mchange:mchange-commons-java:jar:0.2.3.4:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- javax.servlet.jsp:jsp-api:jar:2.0:provided
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- displaytag:displaytag:jar:1.2:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.1:compile
[INFO] |  +- commons-lang:commons-lang:jar:2.3:compile
[INFO] |  +- com.lowagie:itext:jar:1.3:compile
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.7.0:compile
[INFO] |  \- org.slf4j:jcl104-over-slf4j:jar:1.4.2:compile
[INFO] +- taglibs:standard:jar:1.1.2:provided
[INFO] +- junit:junit:jar:4.12:compile
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] +- joda-time:joda-time:jar:2.9.9:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.25:compile
[INFO] |  \- log4j:log4j:jar:1.2.17:compile
[INFO] \- org.aspectj:aspectjweaver:jar:1.9.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.764 s
[INFO] Finished at: 2018-06-17T23:51:28+02:00
[INFO] ------------------------------------------------------------------------

我不知道我是否遗漏了某些内容,或者我不知道如何解释这些信息。我也试过版本1.7.5 for slf4j-log4j12,但我得到同样的东西。

修改

org.apache.commons.logging.impl.SLF4JLocationAwareLog出现在两个不同的路径中:

  • C:\Users\...\.m2\repository\org\slf4j\jcl-over-slf4j\1.5.8\jcl-over-slf4j-1.5.8.jar

  • C:\Users\...\.m2\repository\org\slf4j\jcl104-over-slf4j\1.4.2\jcl104-over-slf4j-1.4.2.jar

但我不知道哪一个失败了,以及如何在从pom.xml更新maven项目时避免加载jar,以免在运行Tomcat时出现错误

2 个答案:

答案 0 :(得分:1)

尝试点击 Ctrl + Shift + t 并在eclipse上输入org.apache.commons.logging.impl.SLF4JLocationAwareLogorg.slf4j.spi.LocationAwareLogger,然后你可以检测包括它们的罐子的名称和版本。我认为你有多个包括它们的罐子,其中一个是无意中加载的,导致NoSuchMethodError

修改

您可以避免错误添加<exclusions>标记:

<dependency>
    <groupId>displaytag</groupId>
    <artifactId>displaytag</artifactId>
    <version>1.2</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl104-over-slf4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>

答案 1 :(得分:0)

DisplayTag是超旧的(但我也使用它),并且依赖于旧的jar。我认为jcl-over-slf4j具有jcl104-over-slf4j的所有功能,因此您不希望两者都在您的应用程序中。试试这个...

<dependency>
    <groupId>displaytag</groupId>
    <artifactId>displaytag</artifactId>
    <version>1.2</version>
    <exclusions>
        <exclusion>
            <artifactId>slf4j-log4j12</artifactId>
            <groupId>org.slf4j</groupId>
        </exclusion>
        <exclusion>
            <artifactId>jcl104-over-slf4j</artifactId>
            <groupId>org.slf4j</groupId>
        </exclusion>
    </exclusions>
</dependency>