Difference between ContextLoaderListener and DispatcherServlet
ContextLoaderListener |
DispatcherServlet |
---|---|
ContextLoaderListener loads the singleton bean specified in the Spring configuration file after reading it and parsing it (using the value provided against contextConfigLocation in web.xml). |
The DispatcherServlet’s job is to communicate requests to the designated Spring MVC controller. |
ContextLoaderListener specified in the web.xml initialises the container called Application Context. |
DispatcherServlet is responsible for creating its own WebApplicationContext. This context controls the handlers, controllers, and view-resolvers. |
The ContextLoaderListener is not essential to a Spring application. |
The DispatcherServlet is essential to a Spring application. |
Application root context is created by ContextLoaderListener. |
DispatcherServlet entries generate a single child application context for each item in the servlet tree. |
ContextLoaderListener vs DispatcherServlet
ContextLoaderListener and DispatcherServlet are two declarations that you should have seen in the web.xml file while configuring Spring MVC using XML. Let’s attempt to comprehend their distinctions and their usefulness inside the framework.ContextLoaderListener adds the web application’s root context to the ServletContext after creating it. Depending on the controller layer technology (Sprouts or Spring MVC), this context can be used to load and unload the beans that are handled by Spring.