users@jersey.java.net

[Jersey] Jersey and CDI in glassfish?

From: Christopher Piggott <cpiggott_at_gmail.com>
Date: Fri, 29 Jun 2012 09:55:28 -0400

Hi,

I'm new to glassfish, and learning about CDI. I'm wondering how this
is supposd to work together with Jersey.

Currently I do a lot of my funny injections via @Context. To
accomplish this, I register a javax.ws.rs.ext.Provider that extends
PerRequestTypeInjectableProvider<Context, MyBean>. This works pretty
well, but I miss having constructor injection.

I tried to do this with CDI by making a simple producer like this:


        public class SomeProducer {
                @Produces
                public Something info()
                {
                        return new Something();
                }
        }

Then I thought I could 1) make my jersey resource class @RequestScoped
2) use @Inject on the constructor.

This doesn't work.

When Jersey creates an instance of the resource, is it aware that it
could do so via CDI? If so what would the lifecycle be:
  - Create resource via CDI
  - Apply jersey's @Context injections where needed (into fields)
  - ?

--Chris