4 Replies Latest reply on May 4, 2007 6:53 PM by Ian Springer

    Problem injecting EJBs

    Nathaniel Stoddard Newbie

      I'm a bit confused on how to inject a simple EJB into a Seam-enabled POJO. I have the field marked with @In(), and configured the "" tag in components.xml, but nothing happens and Seam complains that a value is required by the injection tag and fails.

      <component name="addressService" jndi-name="java:comp/env/ejb/AddressService" auto-create="true" />
      
      ...
      
      @In()
      private AddressService addressService;


      Pretty straight-forward, right? I though it would work, but no. These EJBs are deployed separately, so I can't have them enabled through @Name, ergo the component tag that defines it in components.xml. Am I missing something?

        • 1. Re: Problem injecting EJBs
          Pete Muir Master

          Use the standard @EJB

          • 2. Re: Problem injecting EJBs
            Nathaniel Stoddard Newbie

             

            "petemuir" wrote:
            Use the standard @EJB


            I actually started by using the @EJB annotation, but it didn't work. What Seam code processes the annotation to inject the lookup value?

            @EJB(name = "ejb/AddressService")
            private AddressService addressService;


            I have tried just about every combination of name, mappedName, etc with no positive result. Seam doesn't ever complain about a NameNotFoundException -- the first sign of a problem is the NullPointerException when the code executes. From the looks of it, I'm doing everything I should be doing to configure the ejb-ref on my glassfish.

            Just for the heck of it, I just changed the name to something that clearly doesn't exist -- Seam didn't log any sort of exception to that effect. Maybe Seam isn't processing the annotation at all....

            • 3. Re: Problem injecting EJBs
              Pete Muir Master

              Seam doesn't process @EJB, this is the job of the EJB3 implementation. As long as your bean is configured as an EJB3 bean it should work - but I've never used Glassfish, perhaps ask on the Glassfish forum?

              • 4. Re: Problem injecting EJBs
                Ian Springer Master

                It's the job of the EJB container when the EJB annotation is used within EJBs. I think it would be really nice if Seam processed the EJB annotation when it was used within non-EJB POJOs. Otherwise, you're stuck using JNDI to lookup EJBs that are not Seam components.