Sunday, March 12, 2017

Spring MVC Architecture

In this article we will discuss and learn about Spring MVC architecture.First let us know what is MVC. MVC is an open architecture with multi tiers.MVC is a design pattern stands for Model,view and Controller. It is used to design web applications in standard manner that means it will provide a pattern to design web applications.It can able to provide the roles and responsibilities of the components which we used in MVC pattern or architecture.

Why need to use Spring MVC architecture:

We are using MVC design pattern to develop web applications.It is good to develop your applications where application data and it clearly separates business,navigation and presentation logic proven mechanism for building a thin,clean web-tier.

Spring MVC Components:

Controller:
It handles the navigation logic and and interacts with the service tier for business logic

Model:

 It acts as Contract between the Controller and the View.Model is also responsible contains the data needed to render the view  

View:

This component job is to pull the data from the model and renders the response to the client.


Now we will see the flow of Spring MVC architecture:



Step 1: Whenever we submitting the request from the client(Browser) that request will received by the Dispatcher Servlet. It is not necessary to write any single servlet. Since Spring provides pre-written servlet. This servlet is called Dispatcher Servlet. So the main purpose of Dispatcher Servlet is received all incoming requests and coordinating the different subsystems of Spring MVC. The Dispatcher Servlet also creates webApplicationContext,which contains web specific component such as Controllers and ViewResolver.

Step 2: In this step Dispatcher Servlet will take the help of Handler Mapping and get to know the Controller class name associated with the given request. So request transfer to the Controller.

Step 3: In this step Controller will process the request by executing appropriate methods and returns ModeAndView object(contains Model data and view name)back to the Dispatcher Servlet.

Step 4: The Front Controller then tries to resolve the view(Which can be JSP,Freemaker,Velocity etc) by consulting the View Resolver object.

Step 5: In this step the selected view is then rendered.

Step 6: Finally the rendered view back to client.

Watch video for More details: Spring MVC architecture


See also:

Spring Interview Questions
Struts Interview Questions
Hibernate Interview Questions
JSP Interview Questions
MVC Architecture using JSP and Servlet

1 comment:

High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...