gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:13:55 24 4
gpt4 key购买 nike

我是 Jersey 2 的新手。到目前为止,我使用 Jersey 1.x 和 Spring,并希望使用 HK2 实现。

看完tutorial我写了以下内容:

@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;
}
}

但是我得到以下异常:
org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at Injectee

怎么了?

最佳答案

我在玩 JAXRS 和 @Inject-ing EJB 并遇到同样的错误。使用@EJB,它运行良好。

解决方案是添加 CDI 配置文件并将 bean-discovery-mode="annotated"更改为 bean-discovery-mode="all"

之后,我可以将@Inject 与我的 EJB 一起使用。

这也可能对您有所帮助。

关于java - org.glassfish.hk2.api.UnsatisfiedDependencyException : There was no object available for injection at Injectee,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21265285/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com