1

I have a spring mvc application with log4j 2.9.1. It used to work fine, but all of a sudden, I get

Caused by: java.lang.NoSuchMethodError: org.apache.logging.log4j.ThreadContext.getThreadContextMap()Lorg/apache/logging/log4j/spi/ThreadContextMap;
    at org.apache.logging.log4j.ThreadContextAccess.getThreadContextMap(ThreadContextAccess.java:45)

It seems to occur whenever a logger is getting created like

private static final Logger log = LogManager.getLogger(WebMVCConfig.class);

The following line:

System.out.println("ThreadContext from: " +  ThreadContext.class.getResource("/"
                 + ThreadContext.class.getName().replace('.', '/') + ".class")); 

outputs

WEB-INF/lib/log4j-api-2.9.1.jar!/org/apache/logging/log4j/ThreadContext.class

I started getting this error after using ThreadContext in one of the other applications in my workspace, but I don't have any lines referring to this in this web application.

I've gone through all existing replies to this problem, and it seems like this error is thrown if a log4j-api jar of version 2.7 is present on the build path, but I don't seem to have that jar in the dependencies.

TNAR
  • 21
  • 1
  • 6
  • https://stackoverflow.com/help/how-to-ask refer this. I think this question lacks vital info and context. – Sagar Kharab Aug 31 '21 at 09:38
  • Might be due to the incompatible or missing a desired version of log4j. https://stackoverflow.com/questions/48544014/configure-a-maven-project/48544199 – null Aug 31 '21 at 09:38
  • @SagarKharab, aplogies. I've added more information – TNAR Aug 31 '21 at 10:09

1 Answers1

1

It turns out that it was some issue with the eclipse workspace. I created a new workspace, imported my project there, and it is working fine now.

TNAR
  • 21
  • 1
  • 6