Developing a Spring 3 Framework MVC application step by step tutorial

In this article we will learn how to develop a MVC(CRUD Operation) web application from scratch using the Spring 3 Framework.

Parts of Spring 3 Framework that will be covered in this article.

  • Inversion of Control (IoC)
  • Spring MVC via Annoation
  • Data Access with JDBCTemplate


  • Java SDK 1.6 (Used during this tutorial)
  • Eclipse Indigo (Can also be used Later versions)
  • Spring Framework 3.1
  • HSQLDB v2.2.8 (Any other DB can also be used)

Application to be Developed :

Here in this tutorial we are developing an application where we will Insert(Create) User Details in System. Other CRUD operation look here.

Application Setup :

First create directory for Spring 3 MVC application. Open Eclipse and go to File >> New >> Other. Then select “Dynamic Web Project” from “Select a Wizard” screen.


Now click “Next“. In next(New Dynamic Web Project) screen provide the name of the application as “JBTSpringMVC” and click “Finish“.


Note*: We have selected “Dynamic Web Module version” as 2.5.

Now project has been created and structure of the project would be like.


Add all required Jar in WebContent > WEB-INF > lib . Download all Spring Framework JAR from here .

Required Jars :

  • commons-logging-1.1.1.jar
  • hsqldb.jar (Used for HSQLDB)
  • org.springframework.aop-3.1.1.RELEASE.jar
  • org.springframework.asm-3.1.1.RELEASE.jar
  • org.springframework.beans-3.1.1.RELEASE.jar
  • org.springframework.context-3.1.1.RELEASE.jar
  • org.springframework.core-3.1.1.RELEASE.jar
  • org.springframework.expression-3.1.1.RELEASE.jar
  • org.springframework.jdbc-3.1.1.RELEASE.jar
  • org.springframework.transaction-3.1.1.RELEASE.jar
  • org.springframework.web-3.1.1.RELEASE.jar
  • org.springframework.web.servlet-3.1.1.RELEASE.jar


Configure Web.xml in ‘WEB-INF’ directory:

Now we will modify the web.xml in JBTSpringMVC>>WebContent>>WEB-INF. In web.xml we will define dispatcher servlet(Front End Controller) which will control all request going to web application based on information provided in “url-pattern“. As we want all request url ending with .do to pass through dispatcher  we will provide “<url-pattern>” as “*.do“.

Changed web.xml will look like below.


Now we will create a file named “dispatcher-servlet.xml” in JBTSpringMVC>>WebContent>>WEB-INF. This file contains the view resolver details.

Note*: Name of the file (dispatcher-servlet.xml) is not fixed but it depend on the value of <servlet-name> element in web.xml. What ever servlet-name is defined in web.xml you need to add “-servlet” in it and corresponding .xml will needs to be created in given location(WebContent>>WEB-INF).

Define Dispatcher Servlet XML

In dispatcher servlet we will define viewResolve  which help Spring to resolve the exact location of views.


Create Application Context XML

This XML file we will be used for bean definition and AOP related things. This file has already been configured in Spring via “contextConfigLocation”  property in web.xml.

Look carefully @ the below code in configuration file

These lines will enable annotation config and let spring know which package to scan for Controller.


Create Bean Class:

Create a package named “com.beans” and create a bean class ““. This class will have properties of user and getter ,setter for the same.


Create Controller Class:

Create a package named “com.controller“. Then create controller class “” in given package. Controller class will look like. To let spring know that this is Controller class we have used @Controller annotation.

To map a URL to method we have used @RequestMapping annotation. Now all the request URL as “” will pass throgh “insertMemDtls” method. Given URL can be fired via two methods GET & POST. To differentiate between two types of request method property @RequestMapping annotation can be used. As use can in below code.

In Above code we have used ModelAndView which will provide the views to be rendered. We are passing a string value to ModelAndView. Once passed Spring will try to resolve the exact view by “viewResolver” bean which we have already defined in dispatcher servlet.

As string name provided is “JdbcInsert” Spring will look for jsp named JdbcInsert.jsp in “/WEB-INF/jsp/” location.


Create the View

To insert user details we will required a JSP. Which we will create now. Create a JSP named JdbcInsert.jsp in “/WEB-INF/jsp/”. In jsp we have used form tag from spring framework which will be used to map the property from bean to field in JSP.

Configure Dao Layer

Only Thin left now is DAO layer which actually insert the user details in DB. We are using JdbcTemplate for DB updation JdbcTemplate will require Datasource which we have already configured in applicationContext.xml.




Here is the code for


Hope it now help every one. :)

Everything is now setup. Now DAO layer can insert user details in DB. But we have used HSQLDB for in project.  If you want to know how to configure HSQLDB please visit here. After configure HSQLDB start server and click link http://localhost:8080/JBTSpringMVC/

Application Source Code

A Demo application has been deployed on @

Check this application to know how it works. Till now we have covered only ‘C‘ of CRUD operation rest operation will be cvered in next Articles.

Note*:: This application till now doesn’t have any kind of validation. Which we will explore in later article.

Download Project from below link

About the author

J Singh

Main brain behind this blog/QnA site. She has written all these article as per her personal experience. She has published it mainly to help beginners. These articles might have some problems. So bear with her and let her know if you find any problem in any of the article.