Introduction to Spring MVC

Reading Time: 3 minutes

Spring is the most commonly used framework in Java. It is a general purpose framework i.e it can be used in console applications, desktop applications, web applications, or web services. It is a modular framework i.e it contains different module.

  • Core module : Provides basic IOC implementation
  • web-mvc : Provides an mvc based framework for developing dynamic web-application.
  • ORM-module : Facilitate integration to the framework such as hibernate.

Spring is based on two fundamental concepts

  1. Inversion Of Control (IOC)
  2. Aspect Oriented Programming (AOP)

Spring Modules

Description of modules

  • core : This module provides the implementation of basic IOC container.
  • context : This module provides the implementation of advance IOC container.
  • AOP : This module provides the spring AOP implementation.
  • Tx : This module facilitate AOP based transaction management.
  • JDBC : This module provides implementation of Template design pattern for JDBC operation.
  • ORM : This module facilitate integration of ORM framework. such as Hibernate.
  • web : This module provides implementation of common operations of web applications such as transfer of request data to model object, type-conversion, validation, file uploading and downloading etc.
  • web mvc : This module provides implementation of mvc design-pattern for developing web application.
  • Enterprise integration : This module facilitate integration to enterprise services such as JMS(Java Messaging Services), java mail etc.
  • Testing : This module facilitate IOC based unit and integration testing.

Inversion Of Control (IOC) :

The concept of IOC deals with Object creation, Dependency satisfaction and Life-cycle Management. It states that application programmer should only be concerned with the use of object. Object creation and their management should be handled by an IOC container. The delegation of responsibility from the programmer to the IOC container is known as Inversion Of Control.

Advantages of Inversion Of Control (IOC) :

  • Productivity of the application programmer is increase as they are not responsible for the creation and management of objects.
  • Re-usability of the object is increase because all the objects are created by a single party in the application.
  • Maintenance of the application is simplified as dependency of the objects can be changed through configuration.

Aspect Oriented Programming (AOP) :

Aspect oriented programming is an alternative approach of implementation cross cutting concerns in applications. A concern represent independent task of an operations. If a task participate more than one operation then it said to be cross cutting concern.

How to download and install Spring framework

  1. For Downloading Spring Repository you need to visit https://repo.spring.io/release/org/springframework/spring/. In this website, you will find different spring framework releases. You have to click on latest framework release. Here you will find three files which are:
    • spring-framework-5.1.4.RELEASE-dist.zip
    • spring-framework-5.1.4.RELEASE-docs.zip
    • spring-framework-5.1.4.RELEASE-schema.zip

Now you have to click on “spring-framework-5.1.4.RELEASE-dist.zip” so that it will download.

2. For Installing, You need to extract the “spring-framework-5.1.4.RELEASE-dist.zip” file in your C drive. Now you are able to run your application in spring framework.

Understanding Spring MVC

Spring mvc module provides the implementation of mvc design pattern. Following are the main components of Spring MVC

  • DispatcherServlet : This Servlet acts as the front controller i.e it intercepts all the requests in spring mvc application and controls the flow of their processing.
  • Controller : Controller is a core java class which contains one or more request processing methods. In the spring mvc, controller are equivalent to the Action of struts.
  • RequestMapping : RequestMapping are helper objects which are responsible for RequestMapping a request to a request processing method to a controller. RequestMapping objects are created by the framework using the configuration.
  • ModelAndView : ModelAndView is a helper object which facilitates sharing of processing the result of a controller with the JSP pages.
  • View : View objects are responsible for generating web pages for the end users. Spring supports different presentation technologies for view generation, for each presentation technology which is supported by framework predefined view are made available.
  • JspView : JspView is the default view of the spring mvc. It is equivalent to the dispatcher result as struts.
  • ViewResolver : ViewResolver is a helper component of view. It is responsible for generating a URL JSP page using the view name.

Reference :

https://spring.io/projects/spring-framework

Written by 

Gaurav Dubey is a Java Developer at Knoldus Software LLP. He has done M.CA from Kurukshetra University and completed Bachelor's Degree in Computer Science from M. D. University. He is a tech enthusiast with good knowledge of Java. He is majorly focused in Java practice. On the personal front, he loves to cook and travel.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading