使用SLF4J API的NoSuchMethodError

use*_*949 25 java slf4j

当与slf4j一起使用时,

String test = blahblahblah;
logger.info("{}",test);
Run Code Online (Sandbox Code Playgroud)

跟踪如下

java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;

at org.slf4j.impl.JDK14LoggerAdapter.info(JDK14LoggerAdapter.java:304)
Run Code Online (Sandbox Code Playgroud)

ska*_*man 46

看起来各种SLF4J API和集成库之间的版本不匹配.在版本兼容性方面,SLF4J非常抽象(例如1.6.x不向后兼容1.5.x).

确保各种JAR版本匹配,并确保类路径上没有重复的JAR.

  • 我有类似的问题,但当我匹配sl4j,sl4j-log4j版本为1.7.5在我的情况下它工作正常. (2认同)

Aks*_*kur 7

我收到了这个错误:

SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;
.
.
.
Run Code Online (Sandbox Code Playgroud)

现在我只是注释了pom.xml中的版本,如下所示,它现在正在运行:

    <dependency> 
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <!-- <version>1.6.5</version> -->
    </dependency>
Run Code Online (Sandbox Code Playgroud)