Spring Framework Tutorial – Hello World

Latest Update: 2014/05/21

This post shows how to build a Spring Hello World application.

The following are all steps required to make a Spring hello world program.

1. Set up development environment

IDE: Eclipse IDE for Java EE Developers. The latest version is Eclipse Kepler (4.3.2).

Here is the one you should download:

2. Create a "Dynamic Web Project"

Create a dynamic web project by using the default setting.


After creation, the project explorer view should show:

project explorer

3. Create a index.jsp file

Create an .jsp file named with "index.jsp" under "WebContent" directory. Right click "webContent" --> New --> JSP File. Change the code generated to be the following:

<%@ 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>Hello World </title>
Hello World

4. Create a new server

As a web project runs on an HTTP server, a new server should be setup to hold the web project.

Download Tomcat 7.0 here. Download the core Zip version, and unzip it to a directory (remember this directory). In your eclipse, create a new Server.


Select the directory where you unzipped the tomcat.


Run the project on server, and you should have a welcome page as follows:


5. Add Spring Framework support

Download: Spring Framework 3.1.0.RELEASE is the current production release (requires Java 1.5+)
From: http://www.springsource.org/download
Add the following jar files to "WebContent/WEB-INF/lib" directory.


6. Create Spring MVC

Change web.xml file to be the following:

<?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">

Create springapp-servlet.xml file under WEB-INF direction and copy the following to it:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  <!-- the application context definition for the springapp DispatcherServlet -->
  <bean name="/hello.htm" class="springapp.web.HelloController"/>

Create a class inside "Java Resources" as follows:

package springapp.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class HelloController implements Controller {
	public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
		// TODO Auto-generated method stub
		return new ModelAndView("hello.jsp");

Category >> Spring  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";

  1. NGloom on 2013-12-25

    Nice Introduction.
    Spring projects currently are more often maintained by Maven tools.

  2. james on 2014-10-22
  3. ccna training in pune on 2016-11-19

    Thanks for posting this useful content, Let me share this, . CCNA training in pune

Leave a comment