ContextLoaderListener Spring MVC Example
August 25, 2013
ContextLoaderListener belongs to the package org.springframework.web.context. ContextLoaderListener starts and stops WebApplicationContext. ContextLoaderListener is registered in web.xml If our application is using Log4jConfigListener, then the sequence should be Log4jConfigListener and then ContextLoaderListener in web.xml. ContextLoaderListener is used to inject application context. And the application context file will be used for spring specific configuration.
web.xml
<?xml version="1.0" encoding="ISO-8859-1" ?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>Spring MVC Application</display-name> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>
contextloaderlistener-spring-mvc-example.zip