Friday, 8 January 2016

Wildfly/JBoss slf4j bindig clash with the a webapp slf4j binding

I recently stumbled on a ClassCastException on using the following piece code in a web app deployed on JBoss:

LoggerContext logCtx = (LoggerContext) LoggerFactory.getILoggerFactory();

After some digging I managed to figure out the reason.

JBoss root classloader already uses slf4j  for its own puropses and probably binds its own  implementation. When the web app classloader kicks in, it's already too late, the slf4j is already bound.

A solution would be to intervene at the web app running and load JBoss's slf4j library. I have done that by adding JBoss specific deployment descriptor to the WEB-INF directory, namely, the file jboss-deployment-structure.xml:

<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="">
       <module name="org.slf4j"/>

About Me

My Photo