Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 267
Dejell Avatar asked Jan 21 '14 17:01

Dejell


1 Answers

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.

like image 167
Boris Avatar answered Nov 17 '22 03:11

Boris