Spring Webflow + Spring MVC:Java注释中的Action Bean
我正在使用Spring MVC + Spring Webflow 2。
我想为动作状态定义@Bean,但是我不知道如何在Java Annotation中执行此操作,因为出现此错误:
方法调用:在com.myapp.action.GaraAgenziaAction类型上找不到方法execute()
这里是我想要做的一个例子:spring-webflow-no-actions-were-executed-were-executed
我的豆子:
import org.springframework.webflow.execution.Action;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;
public class GaraAgenziaAction implements Action {
@Override
public Event execute(RequestContext rc) throws Exception {
return new Event(this, "success");
}
}
流XML:
<transition on="fail" to="gara-agenzie"/>
<transition on="success" to="gara-conferma"/>
我的webAppConfig:
@Bean
public Action GaraAgenziaAction()
{
GaraAgenziaAction garaAgenziaAction = new GaraAgenziaAction();
return garaAgenziaAction;
}
非常感谢你
更新解决了感谢@Prasad的建议:
我的Bean(添加@Component):
import org.springframework.stereotype.Component;
import org.springframework.webflow.execution.Action;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;
@Component
public class GaraAgenziaAction implements Action {
@Override
public Event execute(RequestContext rc) throws Exception {
return new Event(this, "success");
}
}
我的webAppConfig(用小写更改bean的名称):
@Bean
public Action garaAgenziaAction()
{
GaraAgenziaAction beanAction = new GaraAgenziaAction();
return beanAction;
}
流XMl配置(将bean名更改为小写,并将flowRequestContext作为参数传递):
<action-state id="action-agenzie">
<evaluate expression="garaAgenziaAction.execute(flowRequestContext)"></evaluate>
<transition on="fail" to="gara-agenzie"/>
<transition on="success" to="gara-conferma"/>
</action-state>
现在它工作正常!
在servlet xml文件中定义action类为:
<!--Class which handles the flow related actions-->
<bean id="garaAgenziaAction" class=" com.myapp.action.GaraAgenziaAction">
</bean>
或者使用Component对其进行注释:
@Component
public class GaraAgenziaAction implements Action{
@Override
public Event execute(RequestContext rc) throws Exception {
return new Event(this, "success");
}
}
在您的流xml访问它为:
<action-state id="action-agenzie">
<evaluate expression="garaAgenziaAction.execute(flowRequestContext)"></evaluate>
<transition on="fail" to="gara-agenzie"/>
<transition on="success" to="gara-conferma"/>
</action-state>
有关配置详情,您可以在此链接的答案中找到它。
链接地址: http://www.djcxy.com/p/39159.html上一篇: Spring Webflow + Spring MVC: Action Bean in Java Annotation