【发布时间】:2014-07-10 22:09:50
【问题描述】:
我正在使用 Spring MVC + Spring Webflow 2。
我想为动作状态定义一个@Bean,但我不知道如何在 Java 注释中执行此操作,因为我收到此错误:
方法调用:找不到方法 execute() com.myapp.action.GaraAgenziaAction 类型
这是我想做的一个例子:spring-webflow-no-actions-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;
}
Flow 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>
现在一切正常!
【问题讨论】:
-
只需在 1) xml bean 定义文件中定义 GaraAgenziaAction bean,如果使用 xml 或 2) 在动作上使用组件注释并在动作状态下调用它。您还观察到,一个实现接口和一个带有 Bean 注释的接口使用相同的类名吗?
-
查看这篇博文中提到的例子:stackoverflow.com/questions/23342621/…,主要是在action-state(for SWF 1)/evaluate-action(for SWF 2 and之后)。虽然 ClassForThisFlow 没有实现动作。您可以在 ClassForThisFlow 中定义任何方法并访问它。
标签: spring spring-mvc action spring-webflow-2