8 Replies Latest reply on Apr 3, 2008 5:08 AM by jwenting

    @EJB Annotation

      Hi there,

      I am trying to initialise EJB within a JSF managed bean using the @EJB annotation.

      However, this is not working out for me. As a result, I am having to use the usual JNDI lookup code in the managed bean's constructor.

      Any help will be much appreciated.

      Best Regards,

      Ashish.

        • 1. Re: @EJB Annotation

          Sorry, I forgot to mention the following:

          JBoss Version - 4.2.2
          JDK Version 1.5.0_11
          Operating System - Windows XP

          Regards,

          Ashish.

          • 2. Re: @EJB Annotation
            jaikiran

            See this http://www.jboss.com/index.html?module=bb&op=viewtopic&t=107353. Look at the post by Wolfgang Knauf, where it's explained how to get the injection working with JSF managed bean

            • 3. Re: @EJB Annotation
              mvlmachado

              hi guys,

              I've tried to reference an ejb (@EJB) within a managed bean, like ashishkulkarni did. In jboss 4.2.2, i had success, but in jboss5.0.0.beta4 the following error occurred:

              20:09:14,359 ERROR [JBossInjectionProvider] Injection failed on managed bean.
              javax.naming.NameNotFoundException: ejb not bound
               at org.jnp.server.NamingServer.getBinding(NamingServer.java:542)
               ...
              20:09:14,406 WARN [lifecycle] executePhase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@17412d0) threw exception
              javax.faces.FacesException: org.apache.jasper.el.JspELException: /index.jsp(13,2) '#{Alo.alo}' Error reading 'alo' on type aloee.Alo
               at javax.faces.component.UIOutput.getValue(UIOutput.java:176)
               ...
              


              Meanwhile, I did the same test with a servlet project and in the jboss5.0.0 it worked but in jboss4.2.2 did not.

              JBoss Versions: 4.2.2.GA and 5.0.0.beta4
              JDK Version - 1.6.0_05
              Windows XP

              remote interface

              @Remote
              public interface AloRemote {
               String alo();
              }
              


              bean code

              @Stateless
              @RemoteBinding(jndiBinding="ejb/AloMundo")
              public class AloBean implements AloRemote {
              
               public String alo() {
               return "Alo, Java EE";
               }
              
              }
              


              managed bean

              public class Alo {
              
               @EJB(name="ejb/AloMundo")
               private AloRemote aloRemote;
              
               public String getAlo() {
               return aloRemote.alo();
               }
              
              }
              


              will the jboss5GA fix this issue? how can I manage to overcome this situation?

              regards,

              marcus

              • 4. Re: @EJB Annotation

                The failure of @EJB binding in JBoss 4 in servlets is documented.
                JBoss 4 does not fully implement the JEE5 standard, and that's one of the omissions.

                What happens when you remove the "ejb/" from the JNDI names?
                Check (with that new bean not included in the application of course so it deploys) what the exact JNDI name is.

                • 5. Re: @EJB Annotation

                  Hi guys,

                  For a JNDI lookup on JBoss, I am using the following pattern:

                  earName/ejbName/interface

                  Example:

                  test01/AloMundo/remote - to access remote interface of AloMundo in test01 ear
                  test01/AloMundo/local - to access local interface of AloMundo in test01 ear

                  Hope this helps.

                  Cheers,

                  Ashish.

                  • 6. Re: @EJB Annotation
                    mvlmachado

                    hi guys,

                    I've tested as suggested by ashish and it worked. i guess this solution a 'hardwire', because you have to change the name property as you need to rename the EAR deployed. my last suggestion was using a user-defined name ("ejb/AloMundo"), instead of jboss standard name ("BeanName/Intf").

                    the code below doesn't work in jboss5.0.0.beta4 but it would be the simplest and standard way to referring an ejb. Surprisingly, the same code works in jboss4.2.2.GA.

                    public class Alo {
                    
                     @EJB
                     private AloRemote aloRemote;
                    
                     public String getAlo() {
                     return aloRemote.alo();
                     }
                    
                    }
                    


                    adopting ashish's strategy, this code works in jboss5:

                    public class Alo {
                    
                     @EJB(name="AloMundo/AloBean/remote")
                     private AloRemote aloRemote;
                    
                     public String getAlo() {
                     return aloRemote.alo();
                     }
                    
                    }
                    


                    AloMundo is earname, AloBean is ejbname

                    regards

                    marcus

                    • 7. Re: @EJB Annotation
                      mvlmachado

                      sorry guys,

                      i had a surprise again the code with @EJB only doesnt work neither with jsf nor with servlets.

                      this solution is using @EJB(name="AloMundo/AloBean/remote") or @EJB(name="ejb/AloMundo"). in the latter, i added in bean class @RemoteBinding(jndiBinding="ejb/AloMundo") annotation.

                      cheers

                      • 8. Re: @EJB Annotation

                        yes, forcing a jndi lookup should work, just as it would have with the J2EE 1.4 spec.
                        You do of course have to supply the correct jndi names.