Dispatcher Servlet, View Resolver and Handler mapping
Control Flow of SpringBootMVC
============================
1. Programmer deploys SpringMVC/SpringBootMVC application in webserver or webapps
2. Deployment activities takes place which involves IOC container creation,DispatcherServlet registration with ServletContainer Pre-Instantiation of Singleton scope spring beans like Controller class,handlermapping,viewResolvers,Service class,DAO class etc. In the mean time necessary dependancy injection also takes place
3. Browser gives request to deployed springmvc application
4. The frontcontroller(DispatcherServlet) traps the request and applies the common system services on the request like logging,auditing,tracking etc,...
5. DispatcherServlet hands over the request to HandlerMapping component to map incoming request with handler method of handler/controller class and gets RequestMapping object from HandlerMapping component having Controller class bean id and HandlerMethod signature(it uses lot of reflection api code internally)
6. DispatcherServlet takes controller bean class id from the recieved RequestMapping object and gets the Controller class object from DispatcherServlet created IOC container.DispatcherServlet also prepares the necessary objects based on the method signature of the handled method collected from RequestMapping Info object.
7. DispatcherServlet calls handler method having necessary object as the arguments on the above received Controller class object.
8. The handler method of the controller class either directly process the request or takes the support of service/DAO and keeps the result in a scope(prefereablly in request scope)
9. The handler method of Controller class returns LVN(logical view name) back to Dispatcher Servlet.
10. DispatcherSerlvet gives LVN to ViewResolver
11. ViewResolver map/link LVN to PhysicalView component and returns View Object having PhysicalViewName and location.
12. DispatcherServlet gets PhysicalViewName and location from the recieved View Object and send the control to Physical view component using rd.forward(,) to format the results gathered from particular scope(preferabley request scope) using presentation logics. These formatted results goes back to DispatcherServlet.
13. DispatcherServlet sends the formatted result to browser as the response.
Own control flow
------------------------
1. Inside a web application, you will do a deployment, Once you do the deployment, deployment activities will happen (deployment means take the application and put it in the container )
2. Deployment activities means, IOC Container should be created, when we create IOC container, Front controller servlet should be created and loaded and that environment should be setup, If this front controller servlet has to be ready even before the loading of other classes, It means load on startup is present on Front controller servlet.
3. Once front controller is ready, Handler mapping classes object should be created, controller classes object should be created and View Resolver objects should be created.
4. For execution for JSP component, JSP tomcat embedded jasper container should be ready.
5. And Assume, If you are creating up a controller->Service->DAO (MVC2 Architecture) then auto wiring should happen, controller, service, DAO object should be created and all that injection should happen and every object should be linked and kept ready
6. All the above things will happen at the deployment activities level only as because IOC Container always performs Eager loading.
7. Once the front controller is ready, from the browser, we will shoot a request, Once you shoot the request, front controller will pickup the Request-URI and request mode and give it to handler mapping.
8. Since the handler mapping object is ready, front controller will take that object and go .
9. Handler mapping will send the RequestMappingInfo[bean id, method name] object to the DispatcherServlet.
10. Now the dispatcher servlet with the mapping information will come to know, which method to call of which object.
12. Method execution will happen, you will get the view name (Logical View name) and same thing will be returned to the front controller.
13. With that Logical view name, Front controller will never get to know whether the component is a JSP component/HTML Component/ Thymleaf component/ Velocity marker
14 . Immediately to identify the physical location of logical view name, It will hand over to View Resolver,
15. If the front controller handles it to View Resolver, In the deployment activities of eager loading, this object already kept ready.
Comments
Post a Comment