Difference between ContextLoaderListener and ContextLoaderServlet

I know that getWebApplicationContext () finds the root WebApplicationContext via ContextLoaderListener or ContextLoaderServlet

But I need to know the difference and when to use it?

+7
source share
2 answers

javadoc for ContextLoaderServlet says everything:

Note that this class is deprecated for containers that implement Servlet API 2.4 or higher, in favor of ContextLoaderListener.

Prior to Servlet API 2.4, the order in which listeners and servlets are initialized is apparently not specified. To make sure that the Spring context is loaded correctly to any other servlets in Servlet 2.3 and the lower container, you will need to use the ContextLoaderServlet and place it as the first to load at startup. Check out this link for more details.

+12
source

context loader loads ex context configuration files (inside web.xml):

 <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> 
+2
source

All Articles