Thursday, February 29, 2024

What is the ContextLoaderListener in Spring MVC? What does it do?

The ContextLoaderListener is one of the important component of Spring MVC framework. It is like any listener defined by Servlet specification and specified in web.xml using <listener> tag. It is loaded when Spring MVC based web application is deployed in any Servlet container e.g. Tomcat. The ContextLoaderLister of Spring MVC is responsible for loading root ApplicationContext for Spring. The application context is the place where Spring bean lives. If you need reference to a Spring bean either its auto-wired or injected by framework or you can get it directly from application context. In Spring MVC based web application, there can be multiple application context e.g. root application context and context local to each DispatcherServlet.