Back to: Spring Framework Tutorials
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.
- Model – The model is responsible for encapsulating the Application data. The Data can be a single entity or a collection of objects.
- Controller – A controller contains the business logic of an application. Here, the @Controller annotation is used to mark the class as the controller.
- 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.
The Sequence of processing an HTTP request in the MVC framework is as follows.
- The Request is 1st received by the Dispatcher Servlet which consults the Mapping Handler so that an appropriate Controller can be called.
- 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.
- The DispatcherServlet takes help from the ViewResolver to pick up the appropriate view for the request generated.
- 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.