【问题标题】:handle Exception in Spring Web Flow在 Spring Web Flow 中处理异常
【发布时间】:2015-11-09 06:24:03
【问题描述】:

你好朋友我正在尝试处理

org.springframework.webflow.execution.repository.snapshot.SnapshotNotFoundException

这个例外,但我没有这样做。 这样我就处理了 SnapshotNotFoundException。

<transition on-exception="org.springframework.webflow.execution.repository.snapshot.SnapshotNotFoundException"
        to="exceptionHandler" />

【问题讨论】:

    标签: spring spring-webflow


    【解决方案1】:

    声明式异常处理似乎不适用于内部 Web Flow 异常。对于这种特殊情况,我们必须实现自定义FlowHandler.handleException()

    类似:

    public class CustomFlowHandler extends AbstractFlowHandler
    {
        @Override
        public String handleException(FlowException e, HttpServletRequest request,
                HttpServletResponse response)
        {
            if (e instanceof FlowExecutionRestorationFailureException)
            {
                if (e.getCause() instanceof SnapshotNotFoundException)
                {
                    // TODO return the desired location string. See javadoc for options
                    return "serverRelative:/missingSnapshot.html";
                }
            }
            return super.handleException(e, request, response);
        }
    }
    

    在Spring配置文件中:

    <!-- custom flow handler -->
    <bean name="your-flow-name" class="yourpackage.CustomFlowHandler"/>
    

    【讨论】:

    • 谢谢@dbreaux。但我在 SFW 中是个新手。如果您再解释一下或使用代码 sn-p 或如何实现这一点,将有很大帮助
    猜你喜欢
    • 2012-10-16
    • 2010-11-09
    • 1970-01-01
    • 1970-01-01
    • 2014-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    相关资源
    最近更新 更多