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

@ExceptionHandler did not take RequestToViewNameTranslator into resolution process [SPR-7298] #11957

Closed
spring-projects-issues opened this issue Jun 17, 2010 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Simon Wong opened SPR-7298 and commented

The issue arose when I use @ExceptionHandler and trying to render the view through ContentNegotiatingViewResolver

@ExceptionHandler(Exception.class)
public Map<String, Object> myExceptionHandler(Exception e) {
    Map<String, Object> modelMap = new HashMap<String, Object>();
    modelMap.put("modelKey", new Object());

    return modelMap;
}

I expect that it will pick the best view through media type, but it fails and get the following exception.

javax.servlet.ServletException: ModelAndView [ModelAndView: materialized View is [null]; model is {modelKey=java.lang.Object@1f2a9da}] neither contains a view name nor a View object in servlet with name 'dispatcher'
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1054)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:801)

After some code tracing, I found that the AnnotationMethodHandlerExceptionResolver.getModelAndView() will return a new ModelAndView object.

...
else if (returnValue instanceof Map) {
return new ModelAndView().addAllObjects((Map) returnValue);
}
...

And in DispatcherServlet.doDispatch(), the default view name didn't be set again after the return of processHandlerException(), that construct a new ModelAndView object


Affects: 3.0.3

Referenced from: commits d49c067

1 votes, 2 watchers

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good catch! As of Spring 3.0.4, DispatcherServlet applies view name translation to error views as well.

This will be available in tomorrow's 3.0.4 snapshot. Feel free to give it an early try...

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.4 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants