Spring-Spring MVC1 Comment

In Spring MVC, XmlViewResolver is used to resolve “view name” based on view beans in the XML file. By default, XmlViewResolver will loads the view beans from /WEB-INF/views.xml, however, this location can be overridden through the “location” property :

In above case, it loads the view beans from “/WEB-INF/spring-views.xml“. See XmlViewResolver example :

  • Controller

A controller class, returns a view, named “WelcomePage“.

  • XmlViewResolver

Register the XmlViewResolver in the Spring’s bean configuration file, loads the view beans from “/WEB-INF/spring-views.xml“.

  • View beans

The “view bean” is just a normal Spring bean declared in the Spring’s bean configuration file, where

  1. id” is the “view name” to resolve.
  2. class” is the type of the view.
  3. url” property is the view’s url location.

File : spring-views.xml

How it works ?
When a view name “WelcomPage” is returned by controller, the XmlViewResolver will find the bean id “WelcomPage” in “spring-views.xml” file, and return the corresponds view’s URL “/WEB-INF/pages/WelcomPage.jsp” back to the DispatcherServlet.
That’s all with XmlViewResolver, check my Spring MVC- View Resolver post to see another ways of view resolvers

1 Comment on this article

Add a comment