handle Exception in Spring Web Flow

2019-04-15 06:48发布

问题:

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