Component.getInstance抛出ClassCastException(GateAction.class,true)

时间:2014-04-25 14:00:58

标签: java resteasy jboss-seam

我是Seam的新手。我正在使用Rest服务,在我的一个休息服务中,我试图通过Component获得Instance,

GateAction gateAction = (GateAction) Component.getInstance(GateAction.class, true); 

因此我得到了错误java.lang.IllegalStateException:没有应用程序上下文活动

然后解决这个问题我将Lifecycle.beginCall()和Lifecycle.endCall()方法调用如下,

Lifecycle.beginCall(); 
GateActionIntf gateAction = (GateActionIntf) Component.getInstance(GateActionImpl.class, true); 
Lifecycle.endCall();

其中GateActionIntf​​是一个接口,GateActionImpl是实现GateActionIntf​​的接缝组件。但现在我得到了ClassCastException。

注意:在我的网络服务项目中,我没有基于component.xml和接缝的配置,我刚刚添加了jboss-seam jar

是否可以获得这样的实例,没有任何component.xml和接缝配置?再次只是突出显示我正在获取实例但是类型转换时抛出ClassCastException。如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

尝试以下内容:

GateActionIntf gateAction = (GateActionImpl) Component.getInstance(GateActionImpl.class, true); 
相关问题