1 2 Previous Next 17 Replies Latest reply on Nov 5, 2009 2:33 AM by 651477

    EJB3 Dependency Injection

    717529
      hi,

      I am using ejb3 with adf managed bean.

      when i inject ejb3 from managed bean , i get only null in the ejb object.
      i am using Jdeveloper 11.111.
      my ejb project and my web project are in separate application.
      i add ejb jar into my web project from library.
      ejb jar will separately deploy into server as jar.
      my web project will deploy into same server.
      is it best practice?

      this is code from my managed bean and session bean.

      @EJB
      RegistrationAuthorityFacadeLocal registrationAuthorityFacade;

      @Stateless
      @Remote
      @Local
      public class RegistrationAuthorityFacadeBean implements RegistrationAuthorityFacade,
      RegistrationAuthorityFacadeLocal {
      With Regards,
      WP
        • 1. Re: EJB3 Dependency Injection
          651477
          Hi,
          please refer to the EJB Spec for the usage of EJB3 annotations:
          "A bean class is permitted to have more than one interface. If a bean class has more than one interface—excluding the interfaces listed below—any business interface of the bean class must be explicitly designated as a business interface of the bean by means of the Local or Remote annotation on the bean class or interface or in the deployment descriptor"

          So in your case, you can specify the EJB like this:
          @Stateless
          @Remote({RegistrationAuthorityFacade.class})
          @Local({RegistrationAuthorityFacadeLocal.class})
          public class RegistrationAuthorityFacadeBean implements RegistrationAuthorityFacade,RegistrationAuthorityFacadeLocal


          Thanks,
          Amy
          1 person found this helpful
          • 2. Re: EJB3 Dependency Injection
            717529
            Hi ,

            Thanks for ur quick response.

            I change the code as u said.

            problem still exists.

            I deploy these application separately.

            is this the problem?

            I check with JNDI tree.
            I found home and ejbObject as below
            //////////////////////////////////
            Binding Name: commoncommon_ejb_jarRegistrationAuthorityFacadeBean_Home
            Class: weblogic.ejb.container.internal.StatelessEJBHomeImpl
            Hash Code: 10995864
            toString Results: weblogic.ejb.container.internal.StatelessEJBHomeImpl@a7c898
            /////////////////////////////////////
            Binding Name: commoncommon_ejb_jarRegistrationAuthorityFacadeBean_RegistrationAuthorityFacade
            Class: sg.com.stee.stars21.common.facade.RegistrationAuthorityFacadeBean_4364xs_RegistrationAuthorityFacadeImpl_1031_WLStub
            Hash Code: 397
            toString Results: weblogic.rmi.internal.CollocatedRemoteRef - hostID: '1977360560047089290S::DefaultDomain:DefaultServer', oid: '397', channel: 'null'
            /////////////////////////////////////////
            I found the following error when i try to initailize into servlet.

            weblogic.application.ModuleException: Could not setup environment
                 at weblogic.servlet.internal.WebAppModule.activateContexts(WebAppModule.java:1361)
                 at weblogic.servlet.internal.WebAppModule.activate(WebAppModule.java:408)
                 at weblogic.application.internal.flow.ModuleStateDriver$2.next(ModuleStateDriver.java:182)
                 at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37)
                 at weblogic.application.internal.flow.ModuleStateDriver.activate(ModuleStateDriver.java:48)
                 Truncated. see log file for complete stacktrace
            weblogic.deployment.EnvironmentException: [J2EE:160200]Error resolving ejb-ref 'sg.com.stee.stars21.testing.Servlet1/registrationAuthorityFacade' from module 'stars21_web-stars21-context-root' of application 'stars21_web'. The ejb-ref does not have an ejb-link and the JNDI name of the target bean has not been specified. Attempts to automatically link the ejb-ref to its target bean failed because no EJBs in the application were found to implement the 'sg.com.stee.stars21.common.facade.RegistrationAuthorityFacadeLocal' interface. Please link or map this ejb-ref to its target EJB and ensure the interfaces declared in the ejb-ref are correct.
                 at weblogic.deployment.BaseEnvironmentBuilder.autowireEJBRef(BaseEnvironmentBuilder.java:426)
                 at weblogic.deployment.EnvironmentBuilder.addEJBReferences(EnvironmentBuilder.java:465)
                 at weblogic.servlet.internal.CompEnv.activate(CompEnv.java:157)
                 at weblogic.servlet.internal.WebAppServletContext.activate(WebAppServletContext.java:3034)
                 at weblogic.servlet.internal.WebAppModule.activateContexts(WebAppModule.java:1359)
                 Truncated. see log file for complete stacktrace



            With Regards,
            WP

            Edited by: user8729650 on Nov 2, 2009 10:49 PM

            Edited by: user8729650 on Nov 2, 2009 10:53 PM
            • 3. Re: EJB3 Dependency Injection
              651477
              Hi,
              it depends on how you access the EJB. if you're injecting the EJB with the local interface, yes please package your web and ejb components in one application (ear).

              if you want to inject the EJB with the remote interface, try to specify the JNDI name of the referenced EJB in the @EJB in your webapp with the mappedName element. In this case, please make sure you've specified the JNDI name of the referenced EJB. you can refer to this post: http://forums.oracle.com/forums/thread.jspa?messageID=3046639&#3046639

              Please refer to EJB Spec chapter16.5 "EJB Reference"


              Thanks,
              Amy
              1 person found this helpful
              • 4. Re: EJB3 Dependency Injection
                717529
                hi,

                Thanks for ur response.


                1.I change the code to remote interface and i add the mappedName from JNDI. as follow.
                but i still have same problem.

                @EJB(mappedName = "RegistrationAuthorityFacade#sg.com.stee.stars21.common.facade.RegistrationAuthorityFacade")
                RegistrationAuthorityFacade registrationAuthorityFacade;

                session bean
                @Stateless(mappedName = "RegistrationAuthorityFacade")

                2.Why i can't use local interface even in separate package. both are on same jvm and same application server.

                With Regards,
                WP
                • 5. Re: EJB3 Dependency Injection
                  651477
                  Hi,
                  1. please verify if the JNDI name "RegistrationAuthorityFacade#sg.com.stee.stars21.common.facade.RegistrationAuthorityFacade" has been bound to JNDI tree. If the JNDI name is bound successfully, it might be a problem...
                  2. currently (until EJB3.0), local business interface is supposed to be served local clients, and we don't expose global jndi name for local business interface. therefore you can't specify the jndi name in your ejb reference declaration like remote interface. The new EJB3.1 Spec is planning to provide the global JNDI name for local business interface too.

                  BTW, how about specifying the mappedName of the @EJB as same as the value in @Stateless?
                  1 person found this helpful
                  • 6. Re: EJB3 Dependency Injection
                    717529
                    hi,

                    I check with JNDI Tree "RegistrationAuthorityFacade#sg.com.stee.stars21.common.facade.RegistrationAuthorityFacade" is bound with jndi tree.

                    I have two interface, one is local for local client and other is remote for remote client.

                    So, how should i do this?

                    I try with same name as in stateless. it has same problem.

                    With Regards,
                    WP
                    • 7. Re: EJB3 Dependency Injection
                      651477
                      Hi,
                      I just realize your client of the EJB is some kind of ADF managed bean, right?
                      I think you can ask the same question in ADF forum: JDeveloper and ADF
                      1 person found this helpful
                      • 8. Re: EJB3 Dependency Injection
                        717529
                        Thanks for the reply.

                        I had try a lot of way to inject it.

                        Even in servlet. not only adf.

                        I realise i did separate package. that is problem.

                        So, do u know how to inject ejb from separate package running on same server?

                        is it possible?

                        With Regards,
                        WP
                        • 9. Re: EJB3 Dependency Injection
                          651477
                          Hi,
                          could you please list the contents of your packages? how many applications (ear)?
                          • 10. Re: EJB3 Dependency Injection
                            717529
                            Hi,

                            I have one ejb-jar. and one ear.

                            inside ear, we have web application.

                            i want to inject ejb from ejb-jar into our web app.

                            both deploy into same weblogic instance.

                            With Regards,
                            WP
                            • 11. Re: EJB3 Dependency Injection
                              651477
                              Hi,
                              so the best practice should be access the EJB through its local interface (for better performance).
                              in this case, you can use element beanName of @EJB to indicate the referenced ejb, like "@EJB(beanName="../ejb.jar#MyEJB")"
                              • 12. Re: EJB3 Dependency Injection
                                717529
                                hi,

                                So, u mean even i deploy both in same server. i can use only remote. isn't it?

                                when I check with my jndi tree, i saw binding name like this "RegistrationAuthorityFacade#sg.com.stee.stars21.common.facade.RegistrationAuthorityFacade".

                                I used it but i have following exception,.

                                Nov 4, 2009 3:30:33 PM SGT> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID '1257319830967' for task '0'. Error is: 'weblogic.application.ModuleException: Could not setup environment'
                                weblogic.application.ModuleException: Could not setup environment
                                     at weblogic.servlet.internal.WebAppModule.activateContexts(WebAppModule.java:1361)
                                     at weblogic.servlet.internal.WebAppModule.activate(WebAppModule.java:408)
                                     at weblogic.application.internal.flow.ModuleStateDriver$2.next(ModuleStateDriver.java:182)
                                     at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37)
                                     at weblogic.application.internal.flow.ModuleStateDriver.activate(ModuleStateDriver.java:48)
                                     Truncated. see log file for complete stacktrace
                                weblogic.deployment.EnvironmentException: [J2EE:160101]Error: The ejb-link 'RegistrationAuthorityFacade#sg.com.stee.stars21.common.facade.RegistrationAuthorityFacade' declared in the ejb-ref or ejb-local-ref 'sg.com.stee.stars21.testing.RegistrationAuthorityBean/registrationAuthorityFacade' in the application module 'stars21_web-stars21-webapp' could not be resolved. The target EJB for the ejb-ref could not be found. Please ensure the link is correct.
                                     at weblogic.deployment.BaseEnvironmentBuilder.addEJBLinkRef(BaseEnvironmentBuilder.java:452)
                                     at weblogic.deployment.EnvironmentBuilder.addEJBReferences(EnvironmentBuilder.java:448)
                                     at weblogic.servlet.internal.CompEnv.activate(CompEnv.java:157)
                                     at weblogic.servlet.internal.WebAppServletContext.activate(WebAppServletContext.java:3034)
                                     at weblogic.servlet.internal.WebAppModule.activateContexts(WebAppModule.java:1359)
                                     Truncated. see log file for complete stacktrace
                                >
                                <Nov 4, 2009 3:30:33 PM SGT> <Error> <Deployer> <BEA-149202> <Encountered an exception while attempting to commit the 9 task for the application 'stars21_web'.>
                                <Nov 4, 2009 3:30:33 PM SGT> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application 'stars21_web'.>
                                <Nov 4, 2009 3:30:33 PM SGT> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
                                weblogic.application.ModuleException: Could not setup environment
                                     at weblogic.servlet.internal.WebAppModule.activateContexts(WebAppModule.java:1361)
                                     at weblogic.servlet.internal.WebAppModule.activate(WebAppModule.java:408)
                                     at weblogic.application.internal.flow.ModuleStateDriver$2.next(ModuleStateDriver.java:182)
                                     at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37)
                                     at weblogic.application.internal.flow.ModuleStateDriver.activate(ModuleStateDriver.java:48)
                                     Truncated. see log file for complete stacktrace
                                weblogic.deployment.EnvironmentException: [J2EE:160101]Error: The ejb-link RegistrationAuthorityFacade#sg.com.stee.stars21.common.facade.RegistrationAuthorityFacade' declared in the ejb-ref or ejb-local-ref 'sg.com.stee.stars21.testing.RegistrationAuthorityBean/registrationAuthorityFacade' in the application module 'stars21_web-stars21-webapp' could not be resolved. The target EJB for the ejb-ref could not be found. Please ensure the link is correct.
                                     at weblogic.deployment.BaseEnvironmentBuilder.addEJBLinkRef(BaseEnvironmentBuilder.java:452)
                                     at weblogic.deployment.EnvironmentBuilder.addEJBReferences(EnvironmentBuilder.java:448)
                                     at weblogic.servlet.internal.CompEnv.activate(CompEnv.java:157)
                                     at weblogic.servlet.internal.WebAppServletContext.activate(WebAppServletContext.java:3034)
                                     at weblogic.servlet.internal.WebAppModule.activateContexts(WebAppModule.java:1359)
                                     Truncated. see log file for complete stacktrace
                                >

                                With Regards,
                                WP
                                • 13. Re: EJB3 Dependency Injection
                                  651477
                                  Hi,
                                  no, i said " access the EJB through its local interface".
                                  you can try:
                                  @EJB(beanName="../ejb.jar#RegistrationAuthorityFacadeBean")
                                  RegistrationAuthorityFacadeLocal registrationAuthorityFacade;
                                  • 14. Re: EJB3 Dependency Injection
                                    717529
                                    Same problem.
                                    /////
                                    @EJB(beanName= "../common_ejb.jar#RegistrationAuthorityFacade")
                                    RegistrationAuthorityFacadeLocal registrationAuthorityFacade;
                                    //////
                                    @EJB(beanName= "../common_ejb.jar#RegistrationAuthorityFacadeBean")
                                    RegistrationAuthorityFacadeLocal registrationAuthorityFacade;

                                    With Regards,
                                    WP
                                    1 2 Previous Next