我的问题是bean没有被注入基类。我读了很多关于这个主题的问题和答案,但没有一个真正帮助我。
我有一个抽象的基类,其中包含一个应该注入的属性:
public abstract class AbstractResearchService<R extends ResearchResult, S extends PredictionResult> {
@EJB(lookup = ResearchManager.JNDI_BINDING)
private ResearchManager researchManager;
protected R submit(final ResearchQuery query) {
// researchManager is null here
}
继承子类是实现远程接口的无状态bean:
@Stateless
@Remote(VoyageResearchService.class)
@WebService(...)
public class VoyageResearchServiceBean extends AbstractResearchService<VoyageResearchResult, VoyagePredictionResult>
implements VoyageResearchService {
@Override
public VoyageResearchResult submitQuery(final VoyageResearchQuery query) {
return submit(query);
}
}
这是带有接口的bean:
@Local
public interface ResearchManager {
String JNDI_BINDING = "java:global/omd-research-manager/ResearchManagerBean";
ResearchResult submitQuery(ResearchQuery query);
}
@Singleton
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class ResearchManagerBean implements ResearchManager {
...
}
我搜索了这个问题并发现了多个声明:
你能证实这些陈述吗?
由于我的VoyageResearchServiceBean正由容器实例化(由于@Stateless注释),我想知道为什么注入不起作用。当调用submit()方法时,属性researchManager为null。
我尝试过:
当我将researchManager注入子类时,它工作正常。但由于我只需要在基类中使用它,我想在那里注入它。
当我尝试使用setter注入时:
@Inject
public void setResearchManager(final ResearchManager researchManager) {
this.researchManager = researchManager;
}
我收到以下错误:
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type ResearchManager with qualifiers @Default
at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Inject public com.in.omd.researchmanager.AbstractResearchService.setResearchManager(ResearchManager)
请你告诉我这里出了什么问题或者我忽略了什么?感谢您的帮助。