Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the default Spring 3 view resolver?

Tags:

spring-mvc

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?

like image 605
gotch4 Avatar asked Jul 07 '11 08:07

gotch4


People also ask

What is the default view resolver in spring boot?

Thymeleaf view resolver works by surrounding the view name with a prefix and suffix. The default values of prefix and suffix are 'classpath:/templates/' and '. html', respectively. Spring Boot also provides an option to change the default value of prefix and suffix by setting spring.

What is the default view resolver in Spring MVC?

2) The InternalResourceViewResolver is also the default view resolver of DispatcherServlet class, which acts as the front controller in the Spring MVC framework.

What is the default view resolver implementation configured by Spring?

An implementation of ViewResolver that accepts a configuration file written in XML with the same DTD as Spring's XML bean factories. The default configuration file is /WEB-INF/views. xml .

What are the view resolver in spring framework?

Spring MVC is a Web MVC Framework for building web applications. In generic all MVC frameworks provide a way of working with views. Spring does that via the ViewResolvers, which enables you to render models in the browser without tying the implementation to specific view technology.


1 Answers

The default is an automatically-registered InternalResourceViewResolver (UrlBasedViewResolver is an abstract superclass of this).

If you declare your own view resolver(s), then the default InternalResourceViewResolver will 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, InternalResourceViewResolver must always be the last view resolver in the chain.

If your controller method returns a View object directly, then no view resolver is necessary, and the view will be rendered directly. Similarly, if you use @ResponseBody, the view resolver is bypassed.

like image 131
skaffman Avatar answered Oct 01 '22 18:10

skaffman