4 Replies Latest reply on Dec 5, 2013 7:36 AM by Juan Andrés Ghigliazza

    EJB injection from web project

    Juan Andrés Ghigliazza Newbie

      We are trying to migrate from GlassFish 3.1 to JBoss EAP 6.1. We have some EARs containing EJBs (with remote interfaces), and some independent web projects using those EJBs. In GlassFish 3.1 we could simply annotate the EJB with javax.ejb.EJB annotation (without attributes), but that is not working in JBoss. Is there a way to use something similar to this in JBoss to obtain remote EJBs? Or do we have to use JNDI lookups?

       

      Thanks very much.

        • 1. Re: EJB injection from web project
          Wolf-Dieter Fink Master

          that should work, you might have a look to the ejb-multi-server quickstart. have a look to the main-app there is a web application and a ejb jar

          • 2. Re: EJB injection from web project
            Juan Andrés Ghigliazza Newbie

            As far as I can see, in that example the web project in app-main is accessing an EJB inside the same EAP. What we want to do, is to access some EJBs that are packaged in a different package of the web project.

            • 3. Re: EJB injection from web project
              Wolf-Dieter Fink Master

              If you look to the JsfController the AppOne AppTwo injections are EJB's deployed in a different application and server.

              1 of 1 people found this helpful
              • 4. Re: EJB injection from web project
                Juan Andrés Ghigliazza Newbie

                I managed to do it, but with the next annotation (being PruebasJbossEjbs-EAR the EAR project containing the EJB, PruebasJbossEjbs the EJB project, pruebas.Prueba1 the class implementing the bean, and pruebas.Prueba1Remote the bean's interface that is in another jar project imported by the EJB project):

                 

                    @Resource(lookup = "java:global/PruebasJbossEjbs-EAR/PruebaJbossEjbs/Prueba1!pruebas.Prueba1Remote")

                 

                I took the parameter from the log when the EAR was deployed, something like:

                 

                09:47:36,539 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-10) JNDI bindings for session bean named Prueba1 in deployment unit subdeployment "PruebaJbossEjbs.jar" of deployment "PruebasJbossEjbs-EAR.ear" are as follows:

                 

                    java:global/PruebasJbossEjbs-EAR/PruebaJbossEjbs/Prueba1!pruebas.Prueba1Remote
                    java:app/PruebaJbossEjbs/Prueba1!pruebas.Prueba1Remote
                    java:module/Prueba1!pruebas.Prueba1Remote
                    java:jboss/exported/PruebasJbossEjbs-EAR/PruebaJbossEjbs/Prueba1!pruebas.Prueba1Remote
                    java:global/PruebasJbossEjbs-EAR/PruebaJbossEjbs/Prueba1
                    java:app/PruebaJbossEjbs/Prueba1
                    java:module/Prueba1

                 

                I don't know if this is the most correct way to do it, and it is not as straight as "@EJB" annotation without parameters in GlassFish, but It works for us.

                 

                Thanks very much Wolf-Dieter.