Reputation: 521
I have googled it but not found satisfactory answer, it would be great if you guys can explain the difference between ContextLoaderListener
and RequestContextListener
.
Upvotes: 27
Views: 18273
Reputation: 158
If you use a Servlet 2.5 web container, with requests processed outside of Spring’s DispatcherServlet (for example, when using JSF or Struts), you need to register the org.springframework.web.context.request.RequestContextListener ServletRequestListener. For Servlet 3.0+, this can be done programmatically via the WebApplicationInitializer interface. Alternatively, or for older containers, add the following declaration to your web application’s web.xml file:
<listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> </web-app>
Upvotes: 5
Reputation: 1
ContextLoaderListener is a bootstrap listener to startup Spring's root WebApplicationContext.
RequestContextListener is used when you want the attributes in your request thread to stay alive.
The point to be noted here is that, the inheritable flag is set to false in the RequestContextListener.
So If you want that a child thread inherits the request attributes then you should try using RequestContextFilter or RequestContextHolder.
Upvotes: 0
Reputation: 2929
I have read that If you use the ContextLoaderListener you don't need the RequestContextListener or Filter. It registers the current request(attributes) in a thread local so that the scoped proxies can use it.
Upvotes: 1
Reputation: 172458
contextloaderlistener :- Bootstrap listener to start up Spring's root WebApplicationContext. Simply delegates to ContextLoader.
requestcontextlistener :- This listener is mainly for use with third-party servlets, e.g. the JSF FacesServlet. Within Spring's own web support, DispatcherServlet's processing is perfectly sufficient.
Upvotes: 16