1

セッションBeanを挿入した次のJSF2コントローラー/bbがあります。ただし、EJBローカルセッションBeanへの参照を取得することはできません。

JSF2バッキング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
4

1 に答える 1

1

CDI管理対象Bean(@Named)とJSF管理対象Bean ()を混合してい@ManagedBeanます。これらの注釈の1つだけが必要です。

どちらかを選択する場合は、正しいスコープクラスをインポートするようにしてください。

CDI:javax.enterprise.context.SessionScoped

JSF:javax.faces.bean.SessionScoped

背景情報については、次の関連する質問と回答を参照してください。

于 2012-07-23T09:31:14.817 に答える