You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Simon Wong opened SPR-7298 and commented
The issue arose when I use
@ExceptionHandler
and trying to render the view through ContentNegotiatingViewResolverI 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
The text was updated successfully, but these errors were encountered: