handle Exception in Spring Web Flow

守給你的承諾、 提交于 2019-12-04 19:03:09

That declarative Exception handling does not seem to work for internal Web Flow exceptions. For this particular case, we had to implement a custom FlowHandler.handleException().

Something like:

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);
    }
}

And in Spring configuration file:

<!-- custom flow handler -->
<bean name="your-flow-name" class="yourpackage.CustomFlowHandler"/>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!