“不满意的依存关系”; -具有相同接口的不同无状态Bean [英] "Unsatisfied Dependencies" - Different Stateless Beans with same Interface
问题描述
我有三个 @Stateless
Bean,它们具有相同的接口。
I have three @Stateless
Beans with the same interface.
public interface ReportService
{
List<String> determineRelevantData();
Report generate(ReportRequest request, Locale locale) throws ServiceFailedException;
}
我将这些bean注入一个外观bean:
I inject the beans in one facade bean:
@Stateless
public class ReportServiceFacadeBean implements ReportServiceFacadeLocal
{
@Inject
private FirstReportBean firstReport;
@Inject
private SecondReportBean secondReport;
@Inject
private ThirdReportBean thirdReport;
[...]
}
我部署时这样,我得到:
When I deploy it this way, I get:
WELD-001408:类型为
的依赖项不满意,带有限定符@Default在
注入点[BackedAnnotatedField] @注入私有
ReportServiceFacadeBean.secondReport
WELD-001408: Unsatisfied dependencies for type SecondReportBean with qualifiers @Default at injection point [BackedAnnotatedField] @Inject private ReportServiceFacadeBean.secondReport
当我取消注释实现bean中的接口时,服务器启动没有任何错误。我在这里想念什么?
When I uncomment the interface in the implementing beans the server starts up without any error. What am I missing here?
推荐答案
与CDI Bean相比,EJB Bean具有一些不同的Bean类型,然后将其用于注入。也就是说,您将希望通过它们的客户端可见部分(即接口(除非您具有无接口视图))注入EJB bean。
EJB beans have a bit different bean types, which are then used for injection, compared to CDI beans. Namely you will want to inject EJB beans by their client-visible parts, meaning interfaces (unless you have no-interface view).
这完全受规范支持,这里是 CDI规范中的一章提到(
This is fully backed by spec, here is one chapter from CDI spec that mentions it (with links to other).
在您的情况下,您将必须引入限定符,然后注入如下所示的bean:
In your case you will have to introduce qualifiers and then inject the beans like:
@Inject
@SomeQualifier
ReportService firstService;
这篇关于“不满意的依存关系”; -具有相同接口的不同无状态Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!