2014-07-09 88 views
1
行動豆在Java中

我在使用Spring MVC +春天的Webflow 2春天的Webflow + Spring MVC的:註釋

我想定義@Bean一個動作狀態,但我不知道如何要做到這一點在Java註解的,因爲我得到這個錯誤:

Method call: Method execute() cannot be found on com.myapp.action.GaraAgenziaAction type

這裏的什麼我想要做的一個例子: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建議:

我的豆(添加@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> 

現在它工作正常!

+0

只需在1)xml bean定義文件中定義GaraAgenziaAction bean(如果使用xml),或者2)在動作上使用Component註釋並將其調用爲動作狀態。你是否也注意到,你正在爲一個實現接口使用同一個類名稱,而另一個則使用Bean註解? – Prasad

+0

檢查在這篇文章中提到的示例:http://stackoverflow.com/questions/23342621/web-flow-add-model-attribute-for-binding-with-form-values/23344985#23344985,其中主要涵蓋配置並訪問操作狀態(針對SWF 1)/評估操作(針對SWF 2及更高版本)的ClassForThisFlow類中的方法。雖然ClassForThisFlow不執行操作。您可以在ClassForThisFlow中定義任何方法並訪問它。 – Prasad

回答

1

定義動作類在servlet的XML文件:

<!--Class which handles the flow related actions--> 
    <bean id="garaAgenziaAction" class=" com.myapp.action.GaraAgenziaAction"> 
    </bean> 

或組件其標註爲:

@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> 

有關配置詳細信息,請參閱link的答案。