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