org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at Injectee

21,936

Solution 1

I was playing around with JAXRS and @Inject-ing EJB and got same error. With @EJB it worked fine.

The solution was to add CDI configuration file and change bean-discovery-mode="annotated" to bean-discovery-mode="all"

After that I could use @Inject with my EJB.

This might help you also.

Solution 2

I assume that the @Service annotation above is the hk2 @Service in which case you should know that @Service does not work automatically in Jersey. Instead you would need to add a binding that would do like a bind(MyProductManager).to(ProductManager) in some Jersey binder

Share:
21,936
Dejell
Author by

Dejell

I like traveling around the world. So far I have been to: USA England Italy Slovania Croatia Jordan South Africa Zimbabwe Botswana France Canada Israel Thailand Switzerland Holland Bulgaria I am going to Vietnam soon

Updated on September 03, 2020

Comments

  • Dejell
    Dejell over 3 years

    I am new to Jersey 2. So far I worked with Jersey 1.x and Spring and would like to use HK2 implementation.

    After reading the tutorial I wrote the following:

    @ManagedBean
    @Path("products")
    @Produces({ MediaType.APPLICATION_JSON })
    public class ProductResource {
    
        @Inject
        ProductManager productManager;
    
        @GET
        public GenericResponseData<List<Product>> getProducts(@QueryParam("condition") Condition condition, @QueryParam("keywords") String keywords) {
            GenericResponseData<List<Product>> res = new GenericResponseData<List<Product>>();
            res.setObject(productManager.getProducts(condition, keywords));
            return res;
        }
    
    }
    @Contract
    public interface ProductManager {
        public List<Product> getProducts(Condition condition, String keywords);
    }
    
    @Service
    public class MyProductManager implements ProductManager {
        @Override
        public List<Product> getProducts(Condition condition, String keywords) {
                return null;
            }
    }
    

    However I get the following exception:

    org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at Injectee
    

    What is wrong?