I am using google guice and wish to integrate it with the JAX-RS extension. On the surface, everything is simple and clean:
final JaxRsApplication application = new JaxRsApplication(component.getContext().createChildContext()); application.setObjectFactory(new ObjectFactory() { @Override public <T> T getInstance(Class<T> jaxRsClass) throws InstantiateException { return Injector.getInstance(jaxRsClass); } }); True, when JAX-RS wishes to create an instance of a resource handler it consults the object factory first, which is excellent. But, there are certain validations that JAX-RS performs on the resource handler type and these validations totally ignore the presence of an object factory. Observer the following stack trace: WrapperUtil.findJaxRsConstructor(Class<?>, String) line: 242 PerRequestRootResourceClass(RootResourceClass).<init>(Class<?>, ThreadLocalizedContext, JaxRsProviders, ExtensionBackwardMapping, Logger) line: 141 PerRequestRootResourceClass.<init>(Class<?>, ThreadLocalizedContext, JaxRsProviders, ExtensionBackwardMapping, Logger) line: 82 ResourceClasses.getPerRequestRootClassWrapper(Class<?>) line: 276 ResourceClasses.addRootClass(Class<?>) line: 104 JaxRsRestlet.addClass(Class<?>) line: 283 JaxRsApplication.add(Application) line: 149 Program.main(String[]) line: 60 What happens is that JAX-RS looks for the public constructors satisfying its instance creation constraints. In my case, the resource handler class has a single public non default constructor not annotated with any of the JAX-RS attributes. Indeed, this constructor is invoked by the dependency injection engine only (guice in my case) from the object factory. I think, that JAX-RS should not fail if it does not find any suitable constructor and the object factory is registered. Seems like a bug? ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2889440