8 Replies Latest reply on May 30, 2013 9:21 AM by meetoblivion

    Weld setter injection of EJBs

    meetoblivion

      Hi all,

       

      I have this really simple snippet

      {code}

      @EJB(lookup = FooDAO.JNDI_LOCATION)

      public void setFooDAO(final FooDAO fooDAO) {

                this.fooDAO = fooDAO;

      }

      {code}

      This exists in my CDI managed beans.  However, it seems the setter doesn't get invoked.  When I switch to field level,

      {code}

      @EJB(lookup = FooDAO.JNDI_LOCATION)

      private FooDAO fooDAO;

      {code}

      Everything is dandy.  As far as I am aware, EJB should be able to be injected just fine.  The only catch is that my CDI bean is defined something like this:

      {code}

      public interface FooService {

      ...

      }

       

      public class FooServiceImpl implements FooService {

      ...

      }

      {code}

      But that should work, no? I'm using JBoss AS 7.1.1 w/ Weld 1.1.10.

        • 1. Re: Weld setter injection of EJBs
          jharting

          Hi John,

           

          this is a known issue in Weld https://issues.jboss.org/browse/WELD-1364

          • 2. Re: Weld setter injection of EJBs
            meetoblivion

            Hmmm, serious sad face right now - http://www.youtube.com/watch?v=oabcM9SOF-E

             

            Anyways, I've been pushing hard at work for creating testable code before writing an arquillian test (e.g. don't use the hammer as a crutch, but as a hammer).  This breaks this.

            Any chance that this can be back ported to the 1.1.x line? Even if I sent you the pull request?

            • 3. Re: Weld setter injection of EJBs
              jharting

              This is planned to be fixed soon for Weld 2.0. PRs are welcome but note that implementing this requires changes to both Weld and AS7 / WildFly integration.

              • 4. Re: Weld setter injection of EJBs
                jaikiran

                Jozef Hartinger wrote:

                 

                PRs are welcome but note that implementing this requires changes to both Weld and AS7 / WildFly integration.

                And as a further FYI to the original poster - WildFly is already on Weld 2.x series which means even if there was a 1.1.x fix for Weld it wouldn't be included in any of the released community AS7 versions (unless one patches it themselves).

                 

                By the way that JIRA doesn't have much details and I'm curious - isn't method level resouce injection tested in CDI TCK? If it is then I would have expected it to be noticed it early in AS7 integration.

                 

                Edited by Jaikiran - To clarify who the FYI was for

                • 5. Re: Weld setter injection of EJBs
                  luksa

                  Is setter injection with the use of @EJB (and not @Inject) even supposed to be supported? I can't find anything re this in the spec. It's clear that it is supported inside EJBs, but where does it say that it should be supported inside CDI beans?

                  • 6. Re: Weld setter injection of EJBs
                    jharting

                    This requirement comes from the EE spec, not CDI spec. Unfortunatelly, the TCK does not test method-level resource injection into CDI beans.

                    • 7. Re: Weld setter injection of EJBs
                      jharting

                      John, did you consider working around by:

                      a) using @Inject setter injection instead of @EJB?

                      b) turning the injected classes in EJBs where the setter injection is supported?

                      • 8. Re: Weld setter injection of EJBs
                        meetoblivion

                        Essentially at this point, we're using field level injection w/ setters to help with the testability.

                         

                        @jaikiran - yes, I would end up patching the local version of weld.  We have to do that anyways, since right now our local builds are based on AS7.1.1 but we upgraded it to Weld 1.1.10