Topic
3 replies Latest Post - ‏2013-01-25T17:08:25Z by SystemAdmin
SystemAdmin
SystemAdmin
590 Posts
ACCEPTED ANSWER

Pinned topic WAS Liberty Profile 8.5.Next Alpha - JAX-RS not supporting CDI?

‏2013-01-25T08:29:23Z |
Hi!

I just tried the new 8.5 alpha version of the liberty profile. While I managed to run the JSF sample with CDI, dependency injection did not work in the JAX-RS applicatoin. Is this a known issue in the alpha?

regards
martin
  • Kenneth.Stephen
    Kenneth.Stephen
    4 Posts
    ACCEPTED ANSWER

    Re: WAS Liberty Profile 8.5.Next Alpha - JAX-RS not supporting CDI?

    ‏2013-01-25T12:38:40Z  in response to SystemAdmin
    Martin,

    While I haven't tried this myself, I'd like to point out that JAX-RS components do not support injection as per the CDI spec. By this, I mean that, unlike servlets, and JSPs, and other JEE components listed out in the spec, just because something is a JAX-RS component, doesn't mean that you can inject a dependency into it. If the JAX-RS component meets the other qualifying criteria for being a CDI managed bean, then this is possible, but not otherwise.

    Does your code work on traditional WAS? If so, then it should work on liberty too. Would you mind posting your code?

    Regards,
    Kenneth
    • SystemAdmin
      SystemAdmin
      590 Posts
      ACCEPTED ANSWER

      Re: WAS Liberty Profile 8.5.Next Alpha - JAX-RS not supporting CDI?

      ‏2013-01-25T17:08:25Z  in response to Kenneth.Stephen
      Hi Kenneth,

      thanks for your reply.

      The answer is Yes, the code works in WAS 8.5.0 but not in the liberty profile. See below the code of the used class. The beans.xml and web.xml are basically empty. The standard output of calling the sample is as follows:

      WAS 8.5.0: context=org.apache.wink.server.internal.contexts.UriInfoImpl@3e852d69 injectedBean=wasdev.sample.cdi.InjectedBean@bd2df72d
      WLP 8.5.1: context=org.apache.wink.server.internal.contexts.UriInfoImpl@972a9bda injectedBean=null

      From within a JSF servlet, the same injection is working.

      regards
      martin

      ----

      @ApplicationPath("resources")
      @Path("/test")
      public class TestApplication extends javax.ws.rs.core.Application {

      @Context
      private UriInfo context;

      @Inject
      private InjectedBean injectedBean;

      @GET
      @Produces("application/xml")
      public String getXml() {
      System.out.println("context=" + context + " injectedBean=" + injectedBean);
      return "<xml>Hello Rest World !</xml>";
      }

      }
  • bergmark
    bergmark
    42 Posts
    ACCEPTED ANSWER

    Re: WAS Liberty Profile 8.5.Next Alpha - JAX-RS not supporting CDI?

    ‏2013-01-25T14:45:37Z  in response to SystemAdmin
    You are correct, @Inject support into EE managed components is a limitation of the Alpha.