Brian Clozel opened SPR-14651 and commented
Without an instance of a RedirectAttributesMethodArgumentResolver
configured in the list of default argument resolvers in ExceptionHandlerExceptionResolver
, the following exception handling method signature is not possible:
@ExceptionHandler(MyCustomException.class)
public String handleMyCustomExceptions(MyCustomException exc, RedirectAttributes redirectAttributes) {
redirectAttributes.addFlashAttribute("errorMessage", "My Custom error message");
return "redirect:/viewName";
}
Reference URL: http://stackoverflow.com/questions/14961869/performing-a-redirect-from-a-spring-mvc-exceptionhandler-method/
Issue Links:
- #19504 Allow PayloadArgumentResolver to only apply to @Payload
annotated parameters
Comment From: spring-projects-issues
Juergen Hoeller commented
Sounds worth doing for 4.3.x still, and easy enough...
Comment From: spring-projects-issues
Brian Clozel commented
This sounds indeed reasonable, but last time I tried I saw that:
- the
RedirectAttributesMethodArgumentResolver
requires aWebDataBinder
to work - the
ExceptionHandlerExceptionResolver
has no way to get aWebDataBinder
;RequestMappingHandlerAdapter
is provided with aConfigurableWebBindingInitializer
for this particular reason. - this asks the question: "should we support data binding through a
WebDataBinder
when resolving and handling controller handler exceptions
I recall talking about this with Rossen Stoyanchev, but I don't remember the outcome of our discussion. Rossen, any opinion about this?
Comment From: spring-projects-issues
Rossen Stoyanchev commented
It requires a DataBinder
only and that's used mainly for type conversion to format attribute values as query parameters. Technically the binder is not even required, it looks like it falls back on toString()
, maybe we can start with that. Alternatively we could inject the ConfigurableWebBindingInitializer
into the ExceptionHandlerExceptionResolver and use it to initialize a DataBinder instance, which will give it access to the ConversionService.
Note also that besides the resolver there is something to be done also after as well. See RequestMappingHandlerAdapter#getModelAndView where the flash map is updated.
Comment From: Jason-zh13
嗯说的不错 点赞吧