Having understood the overall architecture of Spring MVC, Figure 14-4 below pictorially represents the flow of request through various objects in Spring MVC ecosystem.
Figure 14-4. Request flow in a typical Spring MVC web application
The flow of request through various Spring MVC objects can be summarized in order as shown below:
- The client requests for a resource from the server and the request is intercepted by the DispatcherServlet.
- The DispatcherServlet finds the appropriate HandlerMapping.
- The HandlerMapping is responsible for mapping the client request and the appropriate Controller with the help from either Spring configuration file or annotations declared in the classes. Once it determines appropriate Controller, it dispatches the request to the Controller.
- The Controller executes the necessary business logic as necessary and then returns ModelAndView object back to the DispatcherServlet.
- Looking at the values in the ModelAndView object and with the help from ViewResolver object, Spring MVC derives the actual View to be rendered.
- The View object is generated and then sent to the DispactherServlet, which will send it to the Servlet Container to generate the final out which will be sent back to the client.
Figure 14-5 shown below when closely looked, reveals more Spring MVC based objects in the overall request lifecycle in Spring MVC ecosystem. The figure is self-explanatory, and as a single figure can speak louder than a paragraph of words, I felt putting this figure as part of this section explaining Spring MVC’s architecture.
Figure 14-5. Spring MVC Request Lifecycle
On the same lines, Figure 14-6 below shows a simplified version of Spring MVC’s sequence diagram.
Figure 14-6. Simplified sequence diagram of Spring MVC
Page Visitors: 6753