NoSuchMethodError with SLF4J API

前端 未结 8 1995
醉梦人生
醉梦人生 2021-01-03 19:19

When Use with slf4j,

String test = blahblahblah;
logger.info(\"{}\",test);

Trace as below

java.lang.NoSuchMethodError: org.         


        
相关标签:
8条回答
  • 2021-01-03 20:00

    I was getting this error:

    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;
    .
    .
    .
    

    Now I just commented line with version from pom.xml, as shown below, and it is working now:

        <dependency> 
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
          <!-- <version>1.6.5</version> -->
        </dependency>
    
    0 讨论(0)
  • 2021-01-03 20:05

    Also make sure if you deploy in Glassfish externally (not locally) to remove duplicate dependencies in the lib folder of the Glassfish installation on that server.

    In my case, everything worked fine locally but once deployed on a server I got this error.

    0 讨论(0)
  • 2021-01-03 20:06

    In my case, we are having correct version match between the various SLF4J API and integration libraries. But we are also using tika-app jar, which also have SLF4J classes wrapped inside it.

    To check if you are also having some (fat)jar which contains SLF4J classes, On Unix system:

    Go to your WEB-INF/lib/ directory and run following command

    for i in *.jar; do jar -tvf "$i" | grep -Hsi MessageFormatter && echo "$i"; done

    This will print matching result from all jars on console.

    Finally, we replaced tika-app jar by tika-core jar.

    0 讨论(0)
  • 2021-01-03 20:06

    I faced the same problem with Spark Application. It is caused when different versions are mixed.

    We should use something like this :

     "org.slf4j" % "slf4j-log4j12" % "1.7.30" % Test,
     "org.slf4j" % "slf4j-api" % "1.7.30" % Test,
    
    0 讨论(0)
  • 2021-01-03 20:11

    This looks like you have a different version of the MessageFormatter class than your JDK14LoggerAdapter class. Control your classpath.

    0 讨论(0)
  • 2021-01-03 20:12

    I expect that this is because of uncompatible version, like (if you are running your application 6.0 and holding a jar file (slf4j 1.5) or holding both (slf4j 1.5 and 1.6)) then exception might raised.

    suggestion is go for proper version dont place more than one version file (slf4f 1.5 and slf4j 1.6) file in the build path, delete the appropriate one

    and

    then run sure, you will get it.

    0 讨论(0)
提交回复
热议问题