Tuesday, February 5, 2013

Spring and slf4j issue


2013-02-05 13:44:05.963:WARN:oejuc.AbstractLifeCycle:FAILED org.mortbay.jetty.plugin.JettyServer@1ccd159: java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
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.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:272)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:733)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:233)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1222)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:676)


checked the source code, by default spring use commons.logging to write log, but slf4j is being used in the project, so need to use another logging system for spring to use, such as jcl-over-slf4j

to resolve this problem, need to exclude commons logging from spring and replace with jcl-over-slf4j

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.2</version>
</dependency> 
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
                <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions> 
</dependency>

No comments:

Post a Comment