Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RedirectAttributesMethodArgumentResolver to the default argument resolvers in ExceptionHandlerExceptionResolver [SPR-14651] #19217

spring-projects-issues opened this issue Aug 31, 2016 · 3 comments


Copy link

@spring-projects-issues spring-projects-issues commented Aug 31, 2016

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:

public String handleMyCustomExceptions(MyCustomException exc, RedirectAttributes redirectAttributes) {
        redirectAttributes.addFlashAttribute("errorMessage", "My Custom error message");
        return "redirect:/viewName";

Reference URL:

Issue Links:

  • #19504 Allow PayloadArgumentResolver to only apply to @Payload annotated parameters
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 27, 2016

Juergen Hoeller commented

Sounds worth doing for 4.3.x still, and easy enough...

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 9, 2016

Brian Clozel commented

This sounds indeed reasonable, but last time I tried I saw that:

  • the RedirectAttributesMethodArgumentResolver requires a WebDataBinder to work
  • the ExceptionHandlerExceptionResolver has no way to get a WebDataBinder; RequestMappingHandlerAdapter is provided with a ConfigurableWebBindingInitializer 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?

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 9, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.