Tuesday, September 23, 2014

JBOSS - java.lang.NoSuchMethodError: org.jboss.logmanager.LogContext.getAttachment

I came through below error while i was trying to use newer version of hibernate with jboss 5.1.2 EAP. The reason for this is with the classloader. Even though we created a jboss-classloading.xml file and instruct jboss to give priority to our classloader, it still try to pick jboss logging from server class loader than the jar inside war file.


Caused by: java.lang.NoSuchMethodError: org.jboss.logmanager.LogContext.getAttachment(Ljava/lang/String;Lorg/jboss/logmanager/Logger$AttachmentKey;)Ljava/lang/Object;

  at org.jboss.logging.JBossLogManagerProvider.doGetLogger(JBossLogManagerProvider.java:52)

  at org.jboss.logging.JBossLogManagerProvider.getLogger(JBossLogManagerProvider.java:47)

  at org.jboss.logging.Logger.getLogger(Logger.java:2164)

  at org.jboss.logging.Logger.getMessageLogger(Logger.java:2263)

  at org.jboss.logging.Logger.getMessageLogger(Logger.java:2215)

So how to over come this is as follow.


1. Download the zip from here.


2. Unzip it and run ant in the project’s root folder.


3. Copy the resulting .jar in the dist directory to $JBOSS_HOME/server/$PROFILE/deployers.


4. Create a file named jboss-classloading.xml and place it in your deployment’s WEB-INF or META-INF folders with the following contents:


 

<classloading xmlns="urn:jboss:classloading:1.0"

              domain="MyDeploymentDomain"

              parent-domain="NoHibernateNoJBLoggingDomain"

              parent-first="false"

              export-all="NON_EMPTY"

              import-all="true">

</classloading>


5.


The set of packages filtered from your deployment is defined in NoHibernateNoJBLoggingDomain.jar at META-INF/jboss-beans.xml. See below for the default contents of this file:


 

<?xml version="1.0" encoding="UTF-8"?>

<deployment xmlns="urn:jboss:bean-deployer:2.0">

   <bean name="NoHibernateNoJBLoggingDomain" class="com.jboss.examples.classloader.FilteredDefaultDomain">

       <property name="domainName">NoHibernateNoJBLoggingDomain</property>

       <property name="filterPackages">org.hibernate,org.jboss.logmanager</property>

   </bean>

</deployment>

Now You are good to go!!!



1 comment: