1 Reply Latest reply on Mar 20, 2012 8:00 PM by sfcoy

    EJB inject does not work in Listener class when in multiple war

    nfournier

      Hi all,

       

      I have an java ee application that I am trying to convert from JBoss 4 to JBoss 7.1. I tryed JBoss 7 first but I had too many classloading problems. I suspect that my current problem is related to classloading also.

       

      First let me describe the structure of my app. I have a ear that includes 3 wars and 1 jar with stateless sessions beans:

       

      • Main.ear
        • beans.jar
        • web-app-1.war
        • web-app-2.war
        • web-app-3.war

       

      Each of those war have their own code but also share some classes. One of those classes looks like this:

       

      public class AccessAuditListener implements HttpSessionAttributeListener

      {

         @EJB(name = "SeasionBean")

         private SessionBean sessionBean;

       

       

         public void attributeAdded(HttpSessionBindingEvent httpSessionBindingEvent)

         {

            // Do nothing

         }

       

       

         public void attributeRemoved(HttpSessionBindingEvent httpSessionBindingEvent)

         {

            if("attribute".equalsIgnoreCase(httpSessionBindingEvent.getName()))

            {

               sessionBean.doSomething(httpSessionBindingEvent.getValue());

            }

         }

       

       

         public void attributeReplaced(HttpSessionBindingEvent httpSessionBindingEvent)

         {

            // Do nothing.

         }

      }

       

       

      The problem I have is that the first war that gets deployed has its EJB named "SessionBean" properly injected but subsequent wars do not get any ejb reference injected. It is as if while wars would all have their own classloaders but that they would be linked in a way that common classes only get classloaded (and therefore EJB injected) once. In JBoss 4, there was this really useful configuration you could put in the jboss-web.xml (<class-loading java2ClassLoadingCompliance="false"/>) that made sure all wars were 100% isolated.

       

      My question is how can I get the JBoss 4 behavior without getting into the really messy work of turning ear-subdeployments-isolated to true?

       

      Thank you!