Reputation: 17097
I am trying to understand of the SpringContextLoaderListener. i.e why we need it? I loosely understand that it is required to start up Spring. http://www.coderanch.com/t/490458/Spring/purpose-ContextLoaderListener Now what does it mean to start up Spring Application Context? Does it load the dispatcher servlet which is kind of like the main Spring Controller?
Upvotes: 1
Views: 2466
Reputation: 17867
At the core of Spring Framework is a root application context. (i.e. A registry of configured beans.) This context must be somehow initialized. There are many ways to do so now, but in a java web server environment, the most direct way is to use a SpringContextLoaderListener.
Use of the listener allows the root application context to get initialized before components of Spring's Web MVC (such as dispatcher servlets). The beans and configuration of the root context get shared/reused by "child application contexts" created in Dispatcher Servlets, etc.
More info:
http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-servlet (scroll down a few paragraphs to read about dispatcher use of child contexts)
Use a ContextLoaderListener in accordance with DispatchServlet
If you are new to Spring/Java, then I recommend ignoring this next part as it will just serve to confuse you:
Be aware that with Servlet 3.x specification, there are now other less intuitive ways to initialize the application context in a web environment, primarily based on using annotations. These newer techniques are not necessarily better. Starting points for more info:
Upvotes: 3