5 Replies Latest reply on Apr 12, 2011 9:24 AM by jaikiran

    5.1.0.GA - Problems with Dependency Injection

    pi4630

      Hi,

       

      I have two JARs deployed on my JBoss AS. JAR1 contains a SLSB which tries to use a SLSB from JAR2 which exposes a LocalBusiness Interface.

       

      SLSB from JAR1:

       

      {code}

      @Stateless

      @WebService

      public class AnaUniEJB implements AURemoteBusiness, AnaUniWebService {

       

       

                @PersistenceContext(

                                    unitName = "AnaUniDb")

                private EntityManager manager;

                @EJB

                private GVCCLocalBusiness gvcc;

       

       

      {code}

      SLSB from JAR2:

       

      {code}

      @Stateless

      public class GvccBean implements GVCCLocalBusiness {

      ...

      {code}

      When I start JBoss, I get the following message:

       

      {quote}

      WARN  org.jboss.deployment.MappedReferenceMetaDataResolverDeployer (main) Unresolved references exist in JBossMetaData:

      [#AnaUniEJB:AnnotatedEJBReferenceMetaData{name=it.bz.prov.anauni.blogic.AnaUniEJB/gvcc,ejb-ref-type=null,link=null,

      ignore-dependecy=false,mapped/jndi-name=null,resolved-jndi-name=null,beanInterface=interface it.bz.gvcc.interfaces.GVCCLocalBusiness}] {quote}

       

      and this NPE:

       

      {quote}

      ERROR org.jboss.kernel.plugins.dependency.AbstractKernelController (main) Error installing to Start: name=jboss.j2ee:jar=AnagraficaUnificata.jar,name=AnaUniEJB,service=EJB3 state=Create

      java.lang.NullPointerException{quote}

      and finally:

       

      {quote}

      ERROR org.jboss.system.server.profileservice.ProfileServiceBootstrap (main) Failed to load profile: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

       

      DEPLOYMENTS MISSING DEPENDENCIES:

        Deployment "jboss.j2ee:jar=AnagraficaUnificata.jar,name=AnaUniEJB,service=EJB3_endpoint" is missing the following dependencies:

          Dependency "jboss.j2ee:jar=AnagraficaUnificata.jar,name=AnaUniEJB,service=EJB3" (should be in state "Configured", but is actually in state "*ERROR*")

       

      DEPLOYMENTS IN ERROR:

        Deployment "jboss.j2ee:jar=AnagraficaUnificata.jar,name=AnaUniEJB,service=EJB3" is in error due to the following reason(s): java.lang.NullPointerException, *ERROR*{quote}

      Where/what am I doing wrong?

       

      Thanks for your help!

        • 1. Re: 5.1.0.GA - Problems with Dependency Injection
          wolfgangknauf

          Hi,

           

          I hope it helps to add a JBoss-specific "@Depends" annotation to "AnaUniEJB":

           

          @Depends(value = "jboss.j2ee:jar=JAR2.jar,name=GvccBean,service=EJB3")

          @Stateless

          @WebService

          public class AnaUniEJB implements AURemoteBusiness, AnaUniWebService {

           

           

          I am not sure whether the @Depends value is correct. If not: when "GvccBean" is deployed sucessfully, you can find the correct name by looking at the jmx console.

           

          It might also help to force JBoss to first deploy JAR2, then JAR1. Take a look e.g. at those articels:

           

          http://community.jboss.org/wiki/PrefixDeploymentOrder

          http://community.jboss.org/wiki/HowToOrderJBossASDeploymentsByDefiningCustomDependencies

           

          Hope this helps

           

          Wolfgang

          • 2. Re: 5.1.0.GA - Problems with Dependency Injection
            pi4630

            Hi Wolfgang,

             

            unfortunately, it did not work. Here it was I tried:

             

            From the JMX Console, I got the String for @Depends:

             

            {quote}@Depends(value="jboss.j2ee:jar=GVCC.jar,name=GvccBean,service=EJB3"){quote}

            I've put that in the SLSB (1) that tries to make a DI on the other SLSB (2).

             

            I've stopped JBoss AS, deleted the respective jars and deployed first SLSB (2), i.e. the one without dependency. I then read the String on the JMX Console. When I deploy the jar containing SLSB(1), I get the following msg on the console:

             

             

            {quote}ERROR [AbstractKernelController] Error installing to Start: name=jboss.j2ee:jar=AnagraficaUnificata.jar,name=AnaUniEJB,service=EJB3 state=Create

            java.lang.NullPointerException{quote}

             

            and, further

            {quote}ERROR [AbstractKernelController] Error installing to Start: name=jboss.j2ee:jar=AnagraficaUnificata.jar,name=AnaUniEJB,service=EJB3 state=Create

            java.lang.NullPointerException

            ...

            Caused by: java.lang.RuntimeException: javax.naming.NameNotFoundException: env not bound

            {quote}

            I use eclipse IDE, the build path is project independent. Instead, I've copied & pasted the packages from Project 2 (JAR2 = SLSB2) containing the interfaces of SLSB2 into Project 1 (JAR1 = SLSB1). It's just for a proof of concept, I guess one can use maven to manage such dependencies in production use.

             

            Thanks for caring,

            • 3. Re: 5.1.0.GA - Problems with Dependency Injection
              jaikiran

              Injection across independent applications isn't supported https://issues.jboss.org/browse/JBAS-6332. Try adding those 2 jars to a .ear to get it working.

              • 4. Re: 5.1.0.GA - Problems with Dependency Injection
                pi4630

                Hi Jaikiran,

                 

                I've followed your posts about similar discussions around here and JavaRanch; I wasn't quite sure if my problem was due to the same reason. Now it is, thank you.

                 

                So, DI works only between EARs, not JARs. That is, am I able to use DI only inside one EAR or also between different EARs?

                 

                Thank you very much!

                • 5. Re: 5.1.0.GA - Problems with Dependency Injection
                  jaikiran

                  Pasquale Imbemba wrote:

                   

                  Hi Jaikiran,

                   

                  I've followed your posts about similar discussions around here and JavaRanch; I wasn't quite sure if my problem was due to the same reason. Now it is, thank you.

                   


                   

                  You're welcome

                   

                   


                  So, DI works only between EARs, not JARs. That is, am I able to use DI only inside one EAR or also between different EARs?

                   

                   

                  @EJB Injection currently works within a single application. So it won't work between different EARs (or different independently deployed jars).