Thursday, February 4, 2016

java.lang.LinkageError: loader constraint violation org/slf4j/ILoggerFactory

Getting following exception bringing up a Spring Application on Weblogic 11g while trying to instantiate a Spring Controller.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testController' defined in
URL [zip:D:/weblogic/servers/AdminServer/tmp/_WL_user/cservice-ws-ear-1/fd4930/war/WEB-INF/lib/_wl_cls_gen.jar!/
com/testapp/web/controller/TestController.class]:
Instantiation of bean failed; nested exception is java.lang.LinkageError: loader constraint violation:
when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;"
the class loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader) of the current class, org/slf4j/LoggerFactory,
and the class loader (instance of weblogic/utils/classloaders/GenericClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder,
have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1076)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1021)

Fix:

This is happening due to the conflict between my ear lib and weblogic provided slf4j jars. I found a workaround to run this ear on my local. I set the prefer-web-inf-classes to false in weblogic.xml under WEB-INF

<wls:prefer-web-inf-classes>false</wls:prefer-web-inf-classes>

The above would use the file provided by weblogic even if it exists in ear lib.

Here is sample weblogic.xml

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee       http://java.sun.com/xml/ns/javaee/javaee_5.xsd       http://xmlns.oracle.com/weblogic/weblogic-web-app       http://xmlns.oracle.com/weblogic/weblogic-web-app/1.3/weblogic-web-app.xsd">

<wls:container-descriptor>
<wls:prefer-web-inf-classes>false</wls:prefer-web-inf-classes>
</wls:container-descriptor>
    <wls:context-root>deskrev</wls:context-root>

</wls:weblogic-web-app>

No comments:

Post a Comment