8 Replies Latest reply on Oct 24, 2014 3:33 AM by Prasad Deshpande

    ActiveMQ on Wildfly classloading issue

    Prasad Deshpande Expert

      Hi All,

       

      Sorry if this is not the correct forum to post. I was searching for correct forum for Wildfly but failed.

       

      Here is a background on the problem:

       

      Env is JDK 8, Wildfly 8.1

       

      I have a setup where I'm using ActiveMQ resource-adapter for MDB's. Setup is fine & I can see that there are connections made.

       

      15:29:14,593 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-9) JBAS010406: Registered connection factory java:jboss/activemq/amqObjService

      ...

      ...

      15:29:14,709 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-9) JBAS010405: Registered admin object at java:/activemq/queue/obj_sync_in

       

      Now, interestingly MDB's are using Spring for doing work. So in the constructor it creates Spring Application context using below statement:

       

      applicationContext   = new ClassPathXmlApplicationContext("classpath:spring-services-beans.xml");

       

      and then in onMessage method it just get's the bean from spring & calls method.

       

      Case 1:

       

      But above statement throws error saying:

       

      15:29:27,732 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@58461) org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from

      class path resource [spring-services-beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-services-beans.xml] cannot be opened because it does not exist

       

      File spring-services-beans.xml is at the root of EJB jar, but code above is executed by a thread "ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@58461" which is using same classloader that has loaded "org.apache.activemq.ra" module (custom module)

       

      Case 2:

      There is also another thread running which creates/initialises MDB's produces this log:

       

      5:29:27,773 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (default-threads - 7) Loading XML bean definitions from class path resource [spring-services-beans.xml]

       

      This thread correctly uses EJB classloader of EAR & hence finds the "spring-services-beans.xml" file. & everything works fine.

       

      My question is, what is the difference between these two cases, why thread in Case 1 is trying to instantiate MDB?

       

      In my opinion this is something to do with classloading in Wildfly with RA. Why module classloader (that loaded activemq ra) is instantiating MDB's that are in the EAR.?

       

      Interestingly, it all works fine with EAP 6.3.

       

      Any insight will really be helpful...

       

      Thanks,

      Prasad

       

      P.S. Not sure if stack helps to find what could be problem with class loader hierarchy....

      ===================================================================================================================

      2014-10-13 21:51:18,327 INFO  [org.springframework.context.support.ClassPathXmlApplicationContext] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@2f4bfcd3: startup date [Mon Oct 13 21:51:18 BST 2014]; root of context hierarchy

      2014-10-13 21:51:18,328 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) Loading XML bean definitions from class path resource [spring-services-beans.xml]

      2014-10-13 21:51:18,329 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring-services-beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-services-beans.xml] cannot be opened because it does not exist

      2014-10-13 21:51:18,330 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)

      2014-10-13 21:51:18,330 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)

      2014-10-13 21:51:18,330 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)

      2014-10-13 21:51:18,331 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)

      2014-10-13 21:51:18,331 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)

      2014-10-13 21:51:18,332 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251)

      2014-10-13 21:51:18,332 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)

      2014-10-13 21:51:18,332 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)

      2014-10-13 21:51:18,333 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)

      2014-10-13 21:51:18,333 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)

      2014-10-13 21:51:18,333 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)

      2014-10-13 21:51:18,334 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

      2014-10-13 21:51:18,334 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

      2014-10-13 21:51:18,335 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at com.tt.ls.soa.stack.services.worker.TestObjectWorkerManager.init(TestObjectWorkerManager.java:73)

      2014-10-13 21:51:18,335 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at com.tt.ls.soa.stack.services.worker.TestObjectWorkerManager.<init>(TestObjectWorkerManager.java:50)

      2014-10-13 21:51:18,335 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at com.tt.ls.soa.stack.services.worker.TestObjectWorkerManager$$$endpoint3.<init>(Unknown Source)

      2014-10-13 21:51:18,336 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

      2014-10-13 21:51:18,336 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

      2014-10-13 21:51:18,336 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

      2014-10-13 21:51:18,337 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at java.lang.reflect.Constructor.newInstance(Constructor.java:408)

      2014-10-13 21:51:18,337 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at java.lang.Class.newInstance(Class.java:433)

      2014-10-13 21:51:18,337 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.jboss.invocation.proxy.AbstractClassFactory.newInstance(AbstractClassFactory.java:225)

      2014-10-13 21:51:18,338 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.jboss.invocation.proxy.ProxyFactory.newInstance(ProxyFactory.java:270)

      2014-10-13 21:51:18,338 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.jboss.as.ejb3.inflow.JBossMessageEndpointFactory.createEndpoint(JBossMessageEndpointFactory.java:70)

      2014-10-13 21:51:18,338 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.jboss.as.ejb3.inflow.JBossMessageEndpointFactory.createEndpoint(JBossMessageEndpointFactory.java:62)

      2014-10-13 21:51:18,339 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.ra.ServerSessionPoolImpl.createEndpoint(ServerSessionPoolImpl.java:92)

      2014-10-13 21:51:18,339 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.ra.ServerSessionPoolImpl.createServerSessionImpl(ServerSessionPoolImpl.java:76)

      2014-10-13 21:51:18,339 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.ra.ServerSessionPoolImpl.getServerSession(ServerSessionPoolImpl.java:116)

      2014-10-13 21:51:18,340 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.ActiveMQConnectionConsumer.dispatch(ActiveMQConnectionConsumer.java:132)

      2014-10-13 21:51:18,340 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.ActiveMQConnection$3.processMessageDispatch(ActiveMQConnection.java:1872)

      2014-10-13 21:51:18,341 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.command.MessageDispatch.visit(MessageDispatch.java:113)

      2014-10-13 21:51:18,341 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.ActiveMQConnection.onCommand(ActiveMQConnection.java:1852)

      2014-10-13 21:51:18,341 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.transport.ResponseCorrelator.onCommand(ResponseCorrelator.java:116)

      2014-10-13 21:51:18,342 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.transport.MutexTransport.onCommand(MutexTransport.java:50)

      2014-10-13 21:51:18,342 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.transport.WireFormatNegotiator.onCommand(WireFormatNegotiator.java:113)

      2014-10-13 21:51:18,342 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.transport.AbstractInactivityMonitor.onCommand(AbstractInactivityMonitor.java:270)

      2014-10-13 21:51:18,343 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.transport.TransportSupport.doConsume(TransportSupport.java:83)

      2014-10-13 21:51:18,343 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:214)

      2014-10-13 21:51:18,343 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:196)

      2014-10-13 21:51:18,344 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at java.lang.Thread.run(Thread.java:745)

      2014-10-13 21:51:18,344 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) Caused by: java.io.FileNotFoundException: class path resource [spring-services-beans.xml] cannot be opened because it does not exist

      2014-10-13 21:51:18,345 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)

      2014-10-13 21:51:18,345 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)

      2014-10-13 21:51:18,345 ERROR [stderr] (ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@60804) ... 39 more

        • 1. Re: ActiveMQ on Wildfly classloading issue
          jaikiran pai Master

          This looks more of a ActiveMQ thing than WildFly. For whatever reason ActiveMQ is triggering a thread which is trying to load a resource from within the deployment. You'll have to check in ActiveMQ forums to understand what it's trying to do and why.

          • 2. Re: ActiveMQ on Wildfly classloading issue
            Prasad Deshpande Expert

            Thanks for your reply Jaikiran, I see your point about ActiveMQ triggering thread, however, that still doesn't explain why it worked in flawlessly on EAP 6.3. Version of RA & ActiveMQ is exact same what I used with EAP6.3 (in fact I simply copied exact same files from EAP deployment). Only logical explanation I can come up with is something is different in Wildfly 8.1 than EAP6.3, perhaps the way RA module works (like how it delivers message)...? Looks like ActiveMQ is trying to instantiate MDB's (should that be handled by container?) that's why classloader is different. Otherwise I don't see why MDB has module ("com.apache.activemq:main") class loader.

            • 3. Re: ActiveMQ on Wildfly classloading issue
              jaikiran pai Master

              Can't really say for sure why it worked earlier, without knowing what exactly it's doing. Perhaps it was just luck that it was working earlier.

              • 4. Re: Re: ActiveMQ on Wildfly classloading issue
                Prasad Deshpande Expert

                Hey Jaikiran,

                 

                I was able to reproduce problem even with built-in hornetq. All you have to do is put attached ear in deployment folder & following snippet under <jms-destinations> of <subsystem xmlns="urn:jboss:domain:messaging:2.0">:

                 

                                    <jms-queue name="testQueue">

                                        <entry name="queue/test"/>

                                        <entry name="java:jboss/exported/jms/queue/test"/>

                                    </jms-queue>

                 

                You'll get following exception. Not sure if it's problem with classloading that I have defined or with RA classloading.

                 

                For some reason, I can see the classloader that is searching for spring-services-beans.xml is moduleclassloader that has loaded hornetq RA... it's not an application (ear) classloader... hence it fails to see that file on classpath (as it's on the classpath of ear/ejb classloader).

                 

                Here is what exception is:

                ============================================================================================================

                2014-10-16 10:30:50,440 WARN  [org.hornetq.ra] (default-threads - 1) HQ152005: Failure in HornetQ activation org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@2c1c7b26 destination=testQueue destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15): java.lang.RuntimeException: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring-services-beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-services-beans.xml] cannot be opened because it does not exist

                  at org.jboss.as.ejb3.component.EJBComponent.createViewInstanceProxy(EJBComponent.java:174)

                  at org.jboss.as.ejb3.component.EJBComponent.createViewInstanceProxy(EJBComponent.java:160)

                  at org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponent.access$100(MessageDrivenComponent.java:59)

                  at org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponent$2.obtain(MessageDrivenComponent.java:136)

                  at org.jboss.as.ejb3.inflow.JBossMessageEndpointFactory.createEndpoint(JBossMessageEndpointFactory.java:67)

                  at org.jboss.as.ejb3.inflow.JBossMessageEndpointFactory.createEndpoint(JBossMessageEndpointFactory.java:62)

                  at org.hornetq.ra.inflow.HornetQMessageHandler.setup(HornetQMessageHandler.java:197) [hornetq-ra-2.4.1.Final.jar:]

                  at org.hornetq.ra.inflow.HornetQActivation.setup(HornetQActivation.java:339) [hornetq-ra-2.4.1.Final.jar:]

                  at org.hornetq.ra.inflow.HornetQActivation$SetupActivation.run(HornetQActivation.java:794) [hornetq-ra-2.4.1.Final.jar:]

                  at org.jboss.jca.core.workmanager.WorkWrapper.run(WorkWrapper.java:219)

                  at org.jboss.threads.SimpleDirectExecutor.execute(SimpleDirectExecutor.java:33)

                  at org.jboss.threads.QueueExecutor.runTask(QueueExecutor.java:808)

                  at org.jboss.threads.QueueExecutor.access$100(QueueExecutor.java:45)

                  at org.jboss.threads.QueueExecutor$Worker.run(QueueExecutor.java:828)

                  at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_20]

                  at org.jboss.threads.JBossThread.run(JBossThread.java:122)

                Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring-services-beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-services-beans.xml] cannot be opened because it does not exist

                  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)

                  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)

                  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)

                  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)

                  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)

                  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251)

                  at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)

                  at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)

                  at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)

                  at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)

                  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)

                  at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

                  at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

                  at com.test.TestWorkerManager.init(TestWorkerManager.java:46)

                  at com.test.TestWorkerManager.<init>(TestWorkerManager.java:39)

                  at com.test.TestWorkerManager$$$view1.<init>(Unknown Source)

                  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.8.0_20]

                  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [rt.jar:1.8.0_20]

                  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.8.0_20]

                  at java.lang.reflect.Constructor.newInstance(Constructor.java:408) [rt.jar:1.8.0_20]

                  at java.lang.Class.newInstance(Class.java:433) [rt.jar:1.8.0_20]

                  at org.jboss.invocation.proxy.AbstractClassFactory.newInstance(AbstractClassFactory.java:225)

                  at org.jboss.invocation.proxy.ProxyFactory.newInstance(ProxyFactory.java:270)

                  at org.jboss.as.ee.component.ViewService$DefaultViewInstanceFactory.createViewInstance(ViewService.java:271)

                  at org.jboss.as.ee.component.ViewService$View.createInstance(ViewService.java:177)

                  at org.jboss.as.ejb3.component.EJBComponent.createViewInstanceProxy(EJBComponent.java:171)

                  ... 15 more

                Caused by: java.io.FileNotFoundException: class path resource [spring-services-beans.xml] cannot be opened because it does not exist

                  at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)

                  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)

                  ... 40 more

                • 5. Re: Re: Re: ActiveMQ on Wildfly classloading issue
                  jaikiran pai Master

                  I just simplified the entire example to just the basic minimum and here's what the MDB looks like now:

                   

                  package com.test;
                  
                  import javax.ejb.ActivationConfigProperty;
                  import javax.ejb.MessageDriven;
                  import javax.ejb.TransactionAttribute;
                  import javax.ejb.TransactionAttributeType;
                  import javax.ejb.TransactionManagement;
                  import javax.ejb.TransactionManagementType;
                  import javax.jms.Message;
                  import javax.jms.MessageListener;
                  
                  
                  
                  @MessageDriven(activationConfig = {
                          @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
                          @ActivationConfigProperty(propertyName = "destination", propertyValue = "testQueue"),
                          @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") },
                          mappedName="jms/queue/test")
                  @TransactionManagement(TransactionManagementType.BEAN)
                  @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
                  public class TestWorkerManager implements MessageListener {
                  
                      public TestWorkerManager() {
                          System.out.println("Classloader which loaded the MDB is " + this.getClass().getClassLoader());
                          System.out.println("TCCL in constructor of MDB is " + Thread.currentThread().getContextClassLoader());
                      }
                  
                      public void onMessage(Message msg) {
                          System.out.println("TestWorkerManager::onMessage: Message Received: "+msg);
                      }
                  
                  }
                  

                   

                   

                  As you can see, the constructor of the bean now just logs the classloader which loaded the MDB class as well as the thread context classloader when the constructor is being called. Here's the log output when the bean is deployed:

                  11:07:11,163 INFO  [stdout] (default-threads - 1) Classloader which loaded the MDB is ModuleClassLoader for Module "deployment.test.ear.mdb-with-spring.jar:main" from Service Module Loader

                  11:07:11,164 INFO  [stdout] (default-threads - 1) TCCL in constructor of MDB is ModuleClassLoader for Module "org.hornetq.ra:main" from local module loader @1e5941c (finder: local module finder @15ebf57 (roots: /home/me/wildfly-8.1.0.Final/modules,/home/me/wildfly-8.1.0.Final/modules/system/layers/base))

                   

                  The spec mandates that the TCCL be the application's classloader when the component is invoked (even during construction). So it looks like a bug in WildFly 8.1.0 (and if you run and verify the same code against your EAP installation, then a bug there too). This is something we had fixed in early cycles of AS7 [jboss-as7-dev] Issue in EJB ? but looks like has regressed. Please file a WFLY JIRA for this so it gets fixed in 8.2.x and 9.x (I haven't tested in 9.x).

                  • 7. Re: ActiveMQ on Wildfly classloading issue
                    jaikiran pai Master

                    By the way, you should really be doing that initialization in the @PostConstruct method of the MDB. If you move that code to the @PostConstruct, you should be fine even in the current version of EAP/WildFly.

                    • 8. Re: ActiveMQ on Wildfly classloading issue
                      Prasad Deshpande Expert

                      Yep, I agree, this is an existing code written in Scala that I was trying to migrate from 5.1.0 to Wildfly without any changes (as far as possible).  When that didn't work, I wrote above sample equivalent code in java to narrow down problem area. I'll try and see how @PostConstruct can be used with existing Scala program.

                       

                      As for original problem, I refactored spring application context initialization code to use EAR classloader to load *bean.xml & that worked & hence I was convinced that problem lied with Wildfly classloading.

                       

                      Again, as always, thanks for your prompt response & help, Jaikiran!