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

449 Comments Developing a Spring 3 Framework MVC application step by step tutorial

  1. avinash


    I’m a Spring newbie. Can I ask for the source code of this excellent tutorial?


  2. Ajit Shirote

    Hello Admin,

    This tutorial is very helpful for me to develop spring MVC. I am new in spring . could you please share/send me some note that one easy to learn spring core as well spring MVC.

    Thanks in advance,
    Ajit Shirote

  3. hs

    hi please send me the full sourcecode to [email protected]

  4. the_big_cats


    Excellent tutorial :-) ! Would you be so kind as to email me the full source code ? Thanks in advance for your kind consideration !


  5. Mohit

    I am new in Spring MVC and JDBC.
    can you please provide me the complete code of the above example.

  6. Nandhakumar

    I am new this spring tutorial,I have some doubt in this tutorial

    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.

    Do i need to create any new XML with the name of contextConfigLocation in my project or its already configured.

    please reply with clear details,

    Thanks in advance

  7. Anup

    Hi Admin
    I am new to spring and its a nice tutorial to learn.
    IF you can pls send me the source code.

  8. Nitesh


    This tutorial is very useful for me. I am new in spring.
    if you send me the source code ,it will very beneficial for me…


  9. Prad

    the images in this page are not accessible …… since i’m new to Spring pictorial representation can help, plz upload images here . Thank you

    1. Vivekanand Gautam

      Sorry but some how same has been deleted from server. Will try to create new set of images soon.


  10. dungND

    Please send me the source code . I couldn’t find the
    Thanks for the tutorial

  11. Nirmal

    Nice tutorial. Can you please send me the source code [email protected]

  12. srinivas

    Hi admin,
    Nice tutorial. Can you please send me the source code!
    Thanks in advance!
    [email protected]

  13. rafael

    Hi admin,
    Nice tutorial. Can you please send me source code. I am new in spring.
    Thanks in advance!

  14. Ashish

    Can you share the code base for this wonderful demonstration ?

    Please create a download link for codebase. As everyone requires it.

  15. Suparna Bose

    This is a very useful and well explained doc. Can u pls send me the full working source code.Thanx in advance

  16. buying a fitbit

    This is a very good tip particularly to those new to the blogosphere.
    Brief but very accurate information… Thank you for sharing this one.
    A must read post!

  17. Anand

    Excellent and clean tutorial!!

    Admin please send me the source code to

    [email protected]

    Thank you.

  18. LavakumarReddy

    Hi Iam LavakumarReddy Velidandla,I Got Little bit Hope,That I can Develop my Own Web Applications By using Spring,After reading this.It helped lot for me.


    thanks sir to provide this kind complete tuotorial …..
    once again thaks sir…………..

  20. Tapas Choudhury

    Nice tutorial and nicely explain. Can you please send me the source code [email protected].



Leave A Comment

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