users@jersey.java.net

Re: [Jersey] WebApplication.addInjectable gone

From: Martin Probst <mail_at_martin-probst.com>
Date: Fri, 1 Aug 2008 11:47:26 +0200

Hi Paul,

thanks for your help. I'm still running into an issue though. I need
access to a ComponentProvider from within my resource classes, to
instantiate new resources. I.e., I have something like this:

class Books {
   @Inject ComponentProvider provider;
   @POST
   create(Form props) {
     provider.getInstance(Book.class);
   }
}

Because of the chicken-and-egg problem with the component provider, my
servlet setup looks like this:

     @Override
     protected void initiate(ResourceConfig rc, WebApplication wa) {
       rc.getProviderInstances().add(new
ContextComponentProvider(ComponentProvider.class));
       wa.initiate(rc);
       this.provider = wa.getComponentProvider();
     }

And ContextComponentProvider basically injects by returning the local
instance of the component provider. So this looks as if it should
work, but it doesn't :-(

javax.servlet.ServletException:
com.sun.jersey.api.container.ContainerException: Could not get
instance from component provider for type interface
com.sun.jersey.spi.service.ComponentProvider
com
.sun
.jersey
.spi.container.servlet.ServletContainer.service(ServletContainer.java:
311) de.hpi_web.wsminer.Servlet.service(Servlet.java:89)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
com.sun.jersey.api.container.ContainerException: Could not get
instance from component provider for type interface
com.sun.jersey.spi.service.ComponentProvider
[...]
root cause

java.lang.InstantiationException:
com.sun.jersey.spi.service.ComponentProvider
java.lang.Class.newInstance0(Class.java:335)
java.lang.Class.newInstance(Class.java:303)
[...]
Any ideas? How am I supposed to instantiate new resource from within
another resource?
Regards,
Martin