handle Exception in Spring Web Flow

爱⌒轻易说出口 提交于 2019-12-06 12:48:11

问题


Hello Friends Iam trying to handle

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

this exception but iam failed to do so. In this way i handle SnapshotNotFoundException.

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

回答1:


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"/>


来源:https://stackoverflow.com/questions/24116852/handle-exception-in-spring-web-flow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!