我有以下JSF2控制器/ bb,我注入了一个会话bean。但是,它无法获得对EJB本地会话Bean的引用。
JSF2 Backing Bean:
@ManagedBean
@Named("scorecardBackingBean")
@SessionScoped
public class ScorecardBackingBean implements Serializable {
private static final long serialVersionUID = 7231502115861150753L;
@Inject
private IScorecardServiceBean scorecardServiceBean;
@PostConstruct
private void prepareMainLineChart() {
this.mainLineChart = new CartesianChartModel();
List<OrderVolume> orderVolumeList = this.scorecardServiceBean
.getOrderVolume(); //ERROR here, scorecardServiceBean is null.
}
EJB:
@Stateless
public class ScorecardServiceBean implements IScorecardServiceBean {
}
EJB接口:
@Local
public interface IScorecardServiceBean {
List<OrderVolume> getOrderVolume();
}
遇到错误:
java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163)
at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:95)
at org.jboss.as.web.deployment.component.WebComponentInstantiator$2.<init>(WebComponentInstantiator.java:96)
at org.jboss.as.web.deployment.component.WebComponentInstantiator.initializeInstance(WebComponentInstantiator.java:94)
.................
Caused by: java.lang.NullPointerException
at sg.java.bus.controller.scorecard.ScorecardBackingBean.prepareMainLineChart(ScorecardBackingBean.java:79)
at sg.java.bus.controller.scorecard.ScorecardBackingBean.init(ScorecardBackingBean.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptorFactory$ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptorFactory.java:130)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:106)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161)
... 52 more
答案 0 :(得分:1)
您正在混合使用CDI托管bean(@Named
)和JSF托管bean(@ManagedBean
)。这些注释中只有一个是必要的。
如果您选择其中一个,请确保导入正确的范围类。
CDI:javax.enterprise.context.SessionScoped
JSF:javax.faces.bean.SessionScoped
查看这些相关问题&amp;背景信息的答案: