Share on Google+Share on Google+

Spring MVC XmlViewResolver Example

In this tutorial you will learn about the XmlViewResolver

Spring MVC XmlViewResolver Example

org.springframework.web.servlet.view.XmlViewResolver allows us to write view defnition file with the same using the same familiar file. The default file name and location is WEB-INF/views.xml

The following is the mapping for XmlViewResolver in dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
xmlns:xsi="" xmlns:p=""

	<context:component-scan base-package="roseindia.controller" />

	<bean class="org.springframework.web.servlet.view.XmlViewResolver">
		<property name="location">
		<property name="order" value="3" />

The above configuration fill find out the spring-views.xml in the WEB-INF directory.

The following is the configuration for spring-views.xml

<beans xmlns=""

	<bean id="springView" class="org.springframework.web.servlet.view.JstlView">
		<property name="url" value="/WEB-INF/views/view.jsp" />

The controller class for above configurations is as

package roseindia.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

public class AppController {
	public String loadView(Model model) {
		model.addAttribute("greetings", "Welcome");
		return "springView";

Download Complete Source Code


Posted on: August 22, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.