5

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?

4

3 に答える 3

1

上記の @Service アノテーションは hk2 @Service であると仮定します。この場合、Jersey では @Service が自動的に機能しないことを知っておく必要があります。代わりに、Jersey バインダーで bind(MyProductManager).to(ProductManager) のようなバインディングを追加する必要があります。

于 2014-01-26T16:33:42.360 に答える