1 Reply Latest reply: Mar 20, 2012 9:30 AM by Eric Tano RSS

    AS 6.1 EJB dependencies

    Eric Tano Newbie

      Hi,

       

      I'm having some difficulties after switching a legacy project from EJB2.1 with JBoss 5.0 to EJB3 with JBoss AS 6.1. I do have lots of EJB modules, and there are dependencies among the EJBs. I was under the impression by declaring a dependency (with @EJB) this would affect the deployment order, which does not seem to be true.

       

      Suppose you have the following EAR structure:

       

      my.ear

      - ejb1.jar

      |- Bean1 (SLSB)

      - ejb2.jar

      |- Bean2 (SLSB)

      - (... more EJB modules)

       

      Now Bean2 needs Bean1. This will look like this:

       

      ejb1.jar:

      @Stateless(name="Bean1")
      public Bean1 {
      ...
      }
      

       

       

      ejb2.jar:

      @Stateless(name="Bean2")
      @EJB(beanInterface=package1.Bean1.class, name="Bean1")
      public Bean2 {
      ...
      }
      

       

       

      What I see in the log is:

       

      15:16:57,230 INFO  [JBossASKernel] installing bean: jboss.j2ee:ear=my.ear,jar=ejb2.jar,name=Bean2,service=EJB3
      15:16:57,230 INFO  [JBossASKernel]   with dependencies:
      15:16:57,230 INFO  [JBossASKernel]   and demands:
      15:16:57,230 INFO  [JBossASKernel]     jboss-switchboard:appName=my,module=ejb2,name=Bean2; Required: Create
      15:16:57,230 INFO  [JBossASKernel]     jboss.ejb:service=EJBTimerService; Required: Described
      15:16:57,230 INFO  [JBossASKernel]     jboss-injector:topLevelUnit=my.ear,unit=ejb2.jar,bean=Bean2,interceptor=org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor; Required: Described
      15:16:57,231 INFO  [JBossASKernel]     jboss-injector:topLevelUnit=my.ear,unit=ejb2.jar,bean=Bean2,interceptor=org.jboss.weld.integration.ejb.SessionBeanInterceptor; Required: Described
      15:16:57,231 INFO  [JBossASKernel]     jboss-injector:topLevelUnit=my.ear,unit=ejb2.jar,bean=Bean2; Required: Described
      15:16:57,231 INFO  [JBossASKernel]   and supplies:
      15:16:57,231 INFO  [JBossASKernel]     jndi:ejb2/Bean2/local
      15:16:57,231 INFO  [JBossASKernel]     Class:package2.Bean2
      15:16:57,231 INFO  [JBossASKernel]     jndi:Bean2
      15:16:57,231 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=my.ear,jar=ejb2.jar,name=Bean2,service=EJB3) to KernelDeployment of: ejb2.jar
      ...
      15:16:57,268 INFO  [JBossASKernel] installing bean: jboss.j2ee:ear=my.ear,jar=ejb1.jar,name=Bean1,service=EJB3
      15:16:57,268 INFO  [JBossASKernel]   with dependencies:
      15:16:57,268 INFO  [JBossASKernel]   and demands:
      15:16:57,268 INFO  [JBossASKernel]     jboss.ejb:service=EJBTimerService; Required: Described
      15:16:57,268 INFO  [JBossASKernel]     jboss-switchboard:appName=my,module=ejb1,name=Bean1; Required: Create
      15:16:57,268 INFO  [JBossASKernel]     jboss-injector:topLevelUnit=my.ear,unit=ejb1.jar,bean=Bean1; Required: Described
      15:16:57,268 INFO  [JBossASKernel]   and supplies:
      15:16:57,269 INFO  [JBossASKernel]     Class:package1.Bean1
      15:16:57,269 INFO  [JBossASKernel]     jndi:my/Bean1/local-package1.Bean1
      15:16:57,269 INFO  [JBossASKernel]     jndi:Bean1
      15:16:57,269 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=my.ear,jar=ejb1.jar,name=Bean1,service=EJB3) to KernelDeployment of: ejb1.jar
      

       

       

      There is no dependency on ejb1/Bean1 noted. Also, the deployment does not seem to honor the dependency either.

       

      In Bean2 I will at some point perform a JNDI lookup on java:comp/env/Bean1. And in fact, when a client accesses Bean2 during the initalisation/deployment of the server the lookups on "Bean1" from Bean2 will result in NameNotFoundExceptions.

       

      I tried some variants of the @EJB annotation on Bean2 (mostly trying out different combinations of "beanName"  and "mappedName". I would expect that if I did this correctly the dependence would be notet in the log in either "with dependencies:" or "and demands:".

       

      Then I tried this, which actually worked:

       

      ejb2.jar:

      @Stateless(name="Bean2")
      @EJB(beanInterface=package1.Bean1.class, name="Bean1")
      @Depends( { "jboss.j2ee:ear=my.ear,jar=ejb1.jar,name=Bean1,service=EJB3" })
      public Bean2 {
      ...
      }
      

       

       

      HOWEVER, it does not work without the EAR name. As the EJB module is reused in different applications this will not work out.

       

      My preliminary solutions is to use a jboss-app.xml with

       

      <jboss-app>
          <module-order>strict</module-order>
      </jboss-app>
      

       

      and explicit order of the modules in application.xml.

       

      My question is:

       

      Is my workaround with jboss-app.xml the only way to solve this? I would prefer if it would somehow work out just be using the @EJB annotations. Is there any way to get this working?