I'm new to creating REST web services with Jersey 2. I was able to get a few simple cases going now I'm moving on to "real" work.
I create my own instances of ResourceConfig
and populate the ResourceConfig
instances with instances of the REST controller returned by Guice:
<!-- language: lang-java -->
final ResourceConfig rc = new ResourceConfig();
//register an *instance* of a REST controller
rc.register(injector.getInstance(MyRestController.class));
Note that since these REST controller instances were provided by Guice, the instances are populated with all necessary dependencies that are marked with the @Inject
annotation.
However, when I run the above code to bootstrap Jersey, I see an error like the following:
org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(....
Apparently what is happening is that Jersey is also trying to resolve the @Inject
dependencies on the REST controller instance, because it sees the same @Inject
annotations that Guice does.
I don't want Jersey to do any dependency injection. I think there are bridges from Jersey to Guice, but based on program requirements that I can't show here, I need to create the REST controller instances myself and ask the Guice Injector
for them.
My question: How can I disable the dependency injection in Jersey?
I'm currently using the javax.inject.Inject
annotation. Maybe I can use the com.google.inject.Inject
annotation instead, thinking that Jersey won't be looking for these annotations. But still, I would rather just turn off dependency injection in Jersey. How can I do that?
Thank you!!