Configure Multiple View Resolver in Spring MVC

In some previous posts we have seen various types of View Resolvers in Spring MVC
1. Spring MVC XML View Resolver
2. Spring MVC JSP View Resolver
3. Spring MVC ResourceBundle View Resolver

We can also configure these view resolver all together in a single configuration.
Lets see sample code of how to Configure Multiple View Resolver in Spring MVC.

Some points to remember

1. We can assign priority to the view resolver on which order they want to be applied. A property order is used in each bean to give priority to each view resolver.
0 is highest priority and increasing values decreases the priority.

2. The org.springframework.web.servlet.view.InternalResourceViewResolver can always map any request to the correct view, hence it has to be given the lowest priority. This way we give other View Resolver chance to resolve the view names.

Dispatcher Servlet to configure Multiple View Resolver in Spring MVC


When a view name is resolved it will follow the following order to get resolved due to the order we set in the dispachter servlet.
1. ResourceBundleViewResolver (order = 0)
2. XmlViewResolver (order = 1)
3. InternalResourceViewResolver (order = 2)