Skip to content

Jersey 1 @Inject migrated to Jersey 2 stopped working

I am doing a Jersey 1 to Jersey 2 migration of my system. In my code I had @Inject annotation from com.sun.jersey.spi.inject.Inject and @Singleton from com.sun.jersey.spi.resource.Singleton. I’ve changed these to javax.inject.Inject and javax.inject.Singleton.

Since this change I am getting errors while injecting any object annotated with it. My error is this

javax.servlet.ServletException: A MultiException has 4 exceptions.  They are:
1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=APIConnectorHandler,parent=BarcodeSearchClient,qualifiers={},position=-1,optional=false,self=false,unqualified=null,1090224052)
2. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=APIConnectorHandler,parent=RSearchClient,qualifiers={},position=-1,optional=false,self=false,unqualified=null,1247004825)
3. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of errors were found
4. java.lang.IllegalStateException: Unable to perform operation: resolve on


The APIConnectorHandler is Injected both in RSearchClient and BarcodeSearchClient. I first called the endpoint hitting RSearchClient in the flow and then BarcodeSearchClient because of which RSearchClient is also shown as exception #2.

My web.xml looks like this

<?xml version="1.0"?>
When modifying this file, DO NOT FORGET to also modify workspace-web.xml
if necessary so that "brazil-build server" will work.
<web-app xmlns=""

        <description>Spring Expression Language Support</description>

      , com.fasterxml.jackson.jaxrs.json



A few things i did find what that Hk2 is unable to find the beans and stuff but what i’m unable to understand is how did it work in Jersey 1. Where was Jersey 1 @Inject getting the beans from?

PS. This is a super legacy code and i don’t really know why but it has spring integration but none of the objects are created as beans. They are just initialized with new in multiple places. Spring is used to initialize only region specific beans.


Got it working. I had to create a binder class and app class and link it in web.xml. The binder class needed to have binding of all the classes i’m injecting via @Inject and their dependencies.