users@jersey.java.net

Injectable in Jersey

From: Sam Pullara <sam_at_sampullara.com>
Date: Tue, 23 Dec 2008 18:45:36 -0800

Hi All,

I'm trying to use Injectable in Jersey 1.0.1 to pass in my JPA
EntityManager. Based on all the stuff that I have read I was lead to
believe that something like this would work:

     @Provider
     public static class EntityManagerProvider extends
PerRequestTypeInjectableProvider<Context, EntityManager> {

         public EntityManagerProvider() {
             super(EntityManager.class);
         }

         public Injectable<EntityManager>
getInjectable(ComponentContext ic, Context context) {
             return new Injectable<EntityManager>() {
                 public EntityManager getValue() {
                     return ems.get();
                 }
             };
         }
     }

When it starts up it does find it and register it:

INFO: Provider classes found:
   class com.sampullara.chatservice.web.JPAFilter$EntityManagerProvider

And even instantiates an instance of it. However, when my Resource
gets constructed:

     public Users(@Context EntityManager em) {
         this.em = em;
         entity = "User";
     }

It just passes in null and I never get a callback. What am I doing
wrong?

Thanks,
Sam