Jakarta ee CDI依赖注入问题
我在Wildfly应用服务器中正确部署了EJB。我可以使用@EJB注释注入它,但是现在,我想将它封装到cdibean中,以便能够使用@injectannotation注入它。为此,我创建了一个ResourceProducer类,它使用@EJB注入EJB,然后将其包装到CDIBean中 代码如下:Jakarta ee CDI依赖注入问题,jakarta-ee,jboss,dependency-injection,cdi,wildfly,Jakarta Ee,Jboss,Dependency Injection,Cdi,Wildfly,我在Wildfly应用服务器中正确部署了EJB。我可以使用@EJB注释注入它,但是现在,我想将它封装到cdibean中,以便能够使用@injectannotation注入它。为此,我创建了一个ResourceProducer类,它使用@EJB注入EJB,然后将其包装到CDIBean中 代码如下: public class ResourceProducer { @EJB BusinessHandler businessHandler; @Produces @Named("myBusines
public class ResourceProducer {
@EJB
BusinessHandler businessHandler;
@Produces
@Named("myBusinessHandler")
public BusinessHandler getMyBusinessHandler() {
return businessHandler;
}
}
然后在注入点,我使用
@Inject
@Named("myBusinessHandler")
private BusinessHandler handler;
但是Eclipse告诉我“没有任何bean符合注入点的条件[JSR-299§5.2.1]”。我做错了什么?你看到我遗漏的东西了吗。任何帮助都将不胜感激
谢谢 尝试下面的代码将EJB注入CDIBean ResourceProducer.java
@Named
@SessionScoped // or some other scope
public class ResourceProducer { // Your CDI Bean
@Inject
BusinessHandler businessHandler;
}
@Stateless
public class BusinessHandler(){ // Your EJB
...
}
您的EJBBusinessHandler.java
@Named
@SessionScoped // or some other scope
public class ResourceProducer { // Your CDI Bean
@Inject
BusinessHandler businessHandler;
}
@Stateless
public class BusinessHandler(){ // Your EJB
...
}
这就是将EJB注入CDIBean所要做的一切。只是好奇:您可以通过
@inject
直接注入EJB,为什么要使用包装器?