Before you start this Spring 3 MVC tutorial, please refer to this new features in Spring 3 documentation, so that you have a brief idea of what’s new in Spring 3.

In this tutorial, we show you how to develop a Spring 3 MVC hello world example.

Technologies used :

  1. Spring 3.0.5.RELEASE
  2. JDK 1.6
  3. Maven 3
  4. Eclipse 3.6

1. Project Dependency

In Spring 3 @MVC, declares following dependencies in your Maven pom.xml file.

		<!-- Spring 3 dependencies -->

2. Controller & Mapping

In Spring 3, annotation is widely adapted in everywhere. The @RequestMapping is available since 2.5, but now enhanced to support REST style URLs in Spring MVC.

package com.mkyong.common.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
public class HelloController {
	@RequestMapping(method = RequestMethod.GET)
	public String printWelcome(ModelMap model) {
		model.addAttribute("message", "Spring 3 MVC Hello World");
		return "hello";

3. JSP Views

A JSP page to display the value.

File : hello.jsp

	<h1>Message : ${message}</h1>	

4. Spring Configuration

In Spring 3, you still need to enable “auto component scanning” (for controller) and declares “view resolver” manually.

File : mvc-dispatcher-servlet.xml

<beans xmlns=""
	xsi:schemaLocation="    ">
	<context:component-scan base-package="com.mkyong.common.controller" />
		<property name="prefix">
		<property name="suffix">

5. Integrate Web application with Spring

Integration is no different if compare with old Spring 2.5.6, just declares Spring “ContextLoaderListener” and “DispatcherServlet“.

File : web.xml

<web-app id="WebApp_ID" version="2.4"
	<display-name>Spring MVC Application</display-name>

6. Demo

URL : http://localhost:8080/SpringMVC/welcome

spring 3 mvc demo

Download Source Code

Download it – (7 KB)


  1. Spring 3 hello world example
  2. What new in Spring 3
  3. Spring 3 MVC and JSR303 @Valid example
  4. Spring 3 MVC and RSS feed example
  5. Spring 3 MVC and XML example
  6. Spring 3 MVC and JSON example
  7. Spring 3 REST hello world example
  8. Spring 2.5.6 MVC hello world example
  9. Spring 2.5.6 MVC hello world annotation example
Tags :
Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Related Posts

Popular Posts