Friday, October 29, 2010

NoSuchMethodError: org.slf4j.spi.LocationAwareLogger

There is a maven based project that I always use to as skeleton of my new project, inculding Spring, Hibernate, JPA and other staff. So I only need new dependencies as new project required. It always work well until today.

The webapp keeped throw slf4j exception and fail to start:

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:141)


I checked my pom.xml again and again, the slf4j's dependencies are the same as other project:
 
  3.0.4.RELEASE
  3.0.3.RELEASE
  1.6.1
  1.6.9
  2.4.2
  1.2
  UTF-8
 

   log4j
   log4j
   1.2.16
  
  
   org.slf4j
   slf4j-api
   ${slf4j.version}
  
  
   org.slf4j
   jcl-over-slf4j
   ${slf4j.version}
  
  
   org.slf4j
   slf4j-log4j12
   ${slf4j.version}
  

After some google, it is said it might be the jcl bridge incompatibility problem.
Then I checked the eclipse's build path, the jcl bridge became jcl104-over-slf4j. So my problem is I'm mixing the old version of the jcl bridge with the 1.6.1 version of the slf4j-api; this won't work because of a few changes in 1.6.1.


Keep digging, it turns out it's the displaytag's old dependency ruin my project and the solution is:

   displaytag
   displaytag
   ${displaytag.version}
   
    
     org.slf4j
     jcl104-over-slf4j
    
   
  


Therefore, always check the dependency before you add it to your project, especially some old artifact.

5 comments:

Sander said...

I am your fan for today.
I have been searching for 5 hours before your blog.

best regards,

Sander Borra

Ben Wolfe said...

Helped me out a lot, thanks!

FYI: you have "groupid" and "artifactid" when they should be "groupId" and "artifactId"

gabellog said...

Men you save-me after 4 hours y learn a lot tanks.

I fix the problem in a proyec with spring 3, hibernate 3.6.6 , eclipse helios, jboss tools

add this libraries to my proyect

slf4j-1.6.1/slf4j-api-1.6.1.jar
slf4j-1.6.1/slf4j-jcl-1.6.1.jar
slf4j-1.6.1/slf4j-log4j12-1.6.1.jar

Daniel Marthaler said...
This comment has been removed by the author.
Hardik Sanghani said...

hi Ke Cai,

You are great, I spent my 7 hour to solve this problem and suddenly I came across your site and I solve the error in just 2 minute.

Thank you