打印来自 flow.xml 的日志

Printing log from flow.xml

我正在使用 spring 网络流程开发网络应用程序。当我处理 flow.xml 文件时,我得到了这样的决策状态 -

<decision-state id="checkPermissin">    
    <if test="requestParameters.canApprove" then="approve" else="warning" />
</decision-state>  

当请求到达 flow.xml 时,它会从中获取请求参数 canApprove 并测试它是真还是假。然后它进入 approvewarning 状态。

我的问题是 - 我可以从 flow.xml 文件中 log/print canApprove 的状态吗?

您可以在 'decision-state' 的末尾添加一个退出标记,并在类路径上调用任何服务方法、spring bean 或静态方法。

试试这个(未经测试):

<decision-state id="checkPermissin">    
    <if test="requestParameters.canApprove" then="approve" else="warning" />
   <on-exit>
        <evaluate expression="T(org.apache.log4j.Logger).getLogger('someLogger').info(requestParameters.canApprove)"/>
   </on-exit>
</decision-state>

上面的解决方案更像是一个 hack 来满足你的要求。 "proper" 记录这个的方法是扩展一个 FlowExecutionListenerAdapter 并监听你的当前流 + 决策状态 id "checkPermissin" 然后记录你想要的关于那个流的任何东西但是它会涉及更多 setup/coding在 flow.xml 文件之外。 (参见:Catch "dead" session in Spring webflow:该示例用于捕获异常,但可以很容易地调整为记录流中的任何内容)