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

logback

There are a lot reasons I prefer logback over log4j. Look the log output when you fondle Hibernate. Exactly what I’m looking for if something screwed in ORM:

o.h.transaction.JDBCTransaction - commit
o.h.e.d.AbstractFlushingEventListener - processing flush-time cascades
o.h.e.d.AbstractFlushingEventListener - dirty checking collections
o.h.e.d.AbstractFlushingEventListener - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
o.h.e.d.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
org.hibernate.pretty.Printer - listing entities:
org.hibernate.pretty.Printer - org.paradise.user.DBUser{username=Hibernate101, createdBy=system, userId=100, createdDate=Sat Apr 23 14:34:08 SGT 2011}
org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
org.hibernate.SQL - insert into paradise.DBUSER (CREATED_BY, CREATED_DATE, USERNAME, USER_ID) values (?, ?, ?, ?)
o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [VARCHAR] - system
o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [DATE] - Sat Apr 23 14:34:08 SGT 2011
o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - Hibernate101
o.h.type.descriptor.sql.BasicBinder - binding parameter [4] as [INTEGER] - 100

Embedded Link

Hibernate Logging using Logback Logging Framework
In this section, you will learn how to configure logging using Logback Logging Framework. Logback is purposefully created to be successor of the Log4j.