Annoying SLF4J problem in Weblogic server 12c

Using Grails quickly build a web-based application. Deploy and run happily on Tomcat. But after deploy the same war on the latest WebLogic server development version 12c, failed and Exception thrown:

Caused by: 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.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:301)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:240)

After a few drilled investigation, found out bloody WebLogic comes with SLF4J itself, under the directory:

./modules/org.slf4j.api_1.6.1.0.jar
./modules/org.slf4j.ext_1.6.1.0.jar
./modules/org.slf4j.jdk14_1.6.1.0.jar

These SLF4J jar files are conflicting with different version SLF4J jar files in the war file:

17097 10-04-10 10:07 WEB-INF/lib/jcl-over-slf4j-1.5.8.jar
 4464 10-04-10 10:07 WEB-INF/lib/jul-to-slf4j-1.5.8.jar
23445 10-04-10 10:07 WEB-INF/lib/slf4j-api-1.5.8.jar
 9679 10-04-10 10:07 WEB-INF/lib/slf4j-log4j12-1.5.8.jar

After another investigation, the only solution can try is to use SLF4J jar files in the package “overwrite” jar files in WebLogic modules. To do that, add weblogic.xml descriptor file under web-app/WEB-INF directory:

[xml]
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app&quot;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd"&gt;
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.slf4j</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
[/xml]

Basically, it asks WebLogic server to filter out org.slf4j from classloader.

Reference

Leave a comment