Spring MVC Hello World

Spring MVC Hello World

Below are needed to run Spring 3 MVC Hello World:

  • Eclipse 3.0 or above (Download eclipse from http://www.eclipse.org/downloads/ site)
  • JDK 1.6 or above (Download from here: http://www.oracle.com/technetwork/java/javase/downloads/index.html)
  • Tomcat 6 or above (Please follow link to install and configure tomcat in eclipse:Configure and Run Tomcat server in eclipse
  • Spring jars which is already included in project for download in the bottom
  • Spring is very popular framework many companies are adopting it to develop their application. Below is simple spring 3 MVC application to show Hello World.

After all set up and configuration you will see below screen:

Spring MVC Hello World

  • Create dynamic web project in eclipse name: SpringMVCProject (Please use this link if you are not familiar how to create dynamic project in eclipse: Create Dynamic Web Project Eclipse)
  • Once you created dynamic web project in eclipse it should look similar to below

Spring MVC Hello World

  • Please copy below jars in lib folder (You could download project from the bottom it contains everything which is need for the project otherwise you could visit: http://projects.spring.io/spring-framework/ to download all jars)

Spring MVC Hello World

  • Please copy below XML into your web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">





  • Now create file name: dispatcher-servlet.xml inside WEB-INF folder and copy and paste below content
<beans xmlns="http://www.springframework.org/schema/beans"

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

		<property name="prefix">
		<property name="suffix">

  • Create package name com.controller inside src folder

Spring MVC Hello World

  • Create class name: SpringMVCController.java and copy paste below content in it
package com.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 SpringMVCController {
	@RequestMapping(value="/helloWorld.web",method = RequestMethod.GET)
	public String printWelcome(ModelMap model) {

		model.addAttribute("message", "Hello World!!!");
		return "helloWorld";

  • Create jsp folder inside WEB-INF folder
  • Create jsp file name: helloWorld.jsp and copy paste below content in it

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring 3 MVC</title>
<h1>Welcome message: ${message}</h1>


  • You’re done. Final directory structure should be same as below:

Spring MVC Hello World


  • Now it’s time to run this set up in tomcat server. If you haven’t done tomcat set up in eclipse yet please use this link:Configure and Run Tomcat server in eclipse. Now right click project –>Run As –> Run on server. Below is reference:

Spring MVC Hello World

  • Finally you should see below Hello World Message.

Spring MVC Hello World

  • You could also directly execute it from link: http://localhost:7001/SpringMVCProject/helloWorld.web because we have request mapping method = RequestMethod.GET in controller.

Spring MVC Hello World

  • If you want please download above project from below download file.

Note: If you download project code from below and import in your eclipse could see some exception, if you are using different version of JDK, ECLIPSE and Web server. Please use below link to sort out any issues:

download Download Project: SpringMVCProject


Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *