5 Replies Latest reply on Oct 15, 2013 10:23 AM by sfcoy

    @Inject in @WebServiceClient does not work

    lafr

      I have CDI enabled class:

      @Named
      @SessionScoped
      public class Settings extends SessionBase
      {
      }
      

       

      It's injected at different classes within the same war file successfully.

      But injection in a WebServiceClient, also in the same war file

      @WebServiceClient
      public class ItemsService extends Service
      {
          @Inject
          private Settings settings;
      }
      

      does not work. Variable this.settings is null. No error message.

      FacesContext.getCurrentInstance().getApplication().getELResolver().getValue( FacesContext.getCurrentInstance().getELContext(), null, "settings" ) works without problems.

       

      Is there a known restriction?

        • 1. Re: @Inject in @WebServiceClient does not work
          sfcoy

          The javadoc for @javax.xml.ws.WebServiceClient opens with:

          Used to annotate a generated service interface

           

          So, I don't think this class is going to behave in the way that you want anyway...

          • 2. Re: @Inject in @WebServiceClient does not work
            lafr

            The class itself is working fine, for generations of JBoss AS's (4.24, 7.2, 8.0).

            New now only the try to use DI here.

            • 3. Re: @Inject in @WebServiceClient does not work
              sfcoy

              How do instances of ItemsService come into being?

               

              For there to be any chance of injection the container would need to be in control of the instance lifecycle. Other JAX-WS elements such as the service implementation and handlers support the common annotations style of injection (aka @Resource), but web service clients don't rate a mention because it's expected that they are generated code.

               

              In any event, CDI 1.0 and the JAX-WS 2.2 (as required by JavaEE 7) specs were released on the same day (10-Dec-09). So there's no mention of CDI style injection in the JAX-WS spec.
              1 of 1 people found this helpful
              • 4. Re: @Inject in @WebServiceClient does not work
                lafr

                ItemsService is used as a "normal" instance variable in other class, instance created with new:

                @Named

                @ConversationScoped

                public class Kanban

                {

                     private ItemsService itemsService;

                 

                     @PostConstruct

                     void init()

                     {

                          this.itemsService = new ItemsService();

                     }

                }

                 

                So in short the answer is, that Injection is not possible for WebServiceClient's and I have to implement other solution?

                Thanks for your support.

                • 5. Re: @Inject in @WebServiceClient does not work
                  sfcoy

                  Injection never works for objects that are created using "new" without additional processing.

                   

                  For your purpose, however, I can see no reason why ItemsService cannot just be @Injected into Kanban. If it has a default constructor it should just work.

                   

                  It's worth catching up on CDI 1.1 if you haven't already.