I’ve read Spring 3 docs about view resolvers… But in my project I didn’t define any. I just return a ModelAndView or @ResponseBody String from the controller methods. I guess there is a default view resolver (perhaps UrlBasedViewResolver) that is already configured. What is that? Where can I get info in the docs about this?
If I want to add other views like JsonView or XmlView (right now I use a Jsp that renders the data, but I read I can avoid this by passing model Objects directly to special views that will do this for me) how do I deal with this default view resolver?
The default is an automatically-registered
InternalResourceViewResolver(UrlBasedViewResolveris an abstract superclass of this).If you declare your own view resolver(s), then the default
InternalResourceViewResolverwill not be used. You can, if you, wish, simply redeclare it as an explicit bean. If there are multiple view resolvers, then they will be consulted in order until one of them returns a view object. However, because of the way that the servlet API works,InternalResourceViewResolvermust always be the last view resolver in the chain.If your controller method returns a
Viewobject directly, then no view resolver is necessary, and the view will be rendered directly. Similarly, if you use@ResponseBody, the view resolver is bypassed.