Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's wrong for this error

Tags:

java

spring

slf4j

Spring framework throws

Exception in thread "main" 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:159)
    at org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:454)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:392)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)

what's the reason?

like image 809
user496949 Avatar asked Mar 23 '11 10:03

user496949


3 Answers

The reason is wrong version of library added (version conflict).

Check for the version of slf4j 's javadoc and try to figure out ,this method exist with which version ?

like image 192
jmj Avatar answered Sep 21 '22 15:09

jmj


If you are running OSX you might find this is because the following files are included as java extensions:

/Library/Java/Extensions/slf4j-api-1.5.8.jar

/Library/Java/Extensions/slf4j-log4j12-1.5.8.jar

These are loaded by the extension classloader, before your application classloader, so these will be resolved first.

I have no idea why these are there or when they were added but i've only seen this on OSX and in the last year, which might imply they were introduced in java 6.

You can remove\move the files to workaround the problem, but there might be some applications which depend on them.

like image 40
cam Avatar answered Sep 22 '22 15:09

cam


You might be having a class twice in your classpath.

Check the classpath for the occurrences.

like image 26
Kanagaraj M Avatar answered Sep 23 '22 15:09

Kanagaraj M