MVC in Spring Framework

Role of MVC in Spring Framework

In this article, I am going to discuss the Role of MVC in the Spring Framework. Please read our previous article, where we discussed the Modules of Spring Framework.

What is MVC Framework?

The Spring Web MVC framework provides Model-View-Controller (MVC) architecture and ready components that can be used to develop flexible and loosely coupled web applications. The MVC architecture results in separating the different aspects of the application. The Basic elements of an MVC architecture are as follows.

  1. Model – The model is responsible for encapsulating the Application data. The Data can be a single entity or a collection of objects.
  2. Controller – A controller contains the business logic of an application. Here, the @Controller annotation is used to mark the class as the controller.
  3. View – A view represents the provided information in a particular format. Generally, JSP+JSTL is used to create a view page. Although spring also supports other view technologies such as Apache Velocity, Thymeleaf, and FreeMarker.
Role of MVC in Spring Framework

Spring MVC is a framework that is used to develop web Applications following the Model view controller design pattern. The framework implements all the basic features of the core spring framework like Dependency Injection and Inversion of Control. The Spring MVC framework is designed around the DispatcherServlet which is responsible for dispatching the requests to the handlers. The default handler is based on the @controller and @RequestMapping annotations. The request process workflow of a Spring MVC application is shown below.

Role of MVC in Spring Framework

The Sequence of processing an HTTP request in the MVC framework is as follows.

  1. The Request is 1st received by the Dispatcher Servlet which consults the Mapping Handler so that an appropriate Controller can be called.
  2. The Controller after receiving the request calls the appropriate HTTP Service methods like GET or POST. The Service method sets the data elements to the Model and return the view name to the DispatcherServlet.
  3. The DispatcherServlet takes help from the ViewResolver to pick up the appropriate view for the request generated.
  4. After picking up the appropriate view from the list of views, the DispatcherServlet passes the data of the Model to the view which is finally sent as the response and rendered in the Web Browser.

Here, in this article, I try to explain the Role of MVC in Spring Framework and I hope you enjoy this MVC in Spring Framework article.

Leave a Reply

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