Contexts in Spring Framework!

Notes from this great book!
  • The Spring Framework container comes in the form of one or more Application Contexts, represented by the ApplicationContext interface.
  • An Application Context manages a set of beans, Java objects that perform business logic, execute tasks, persist and retrieve persisted data, respond to HTTP requests, and more. 
  • Spring-Managed beans are automatically eligible for dependency injection, message notification, scheduled method execution, bean validation, and other crucial Spring services.
  • For programmatically configuring Spring Framework using Java,  instead of the traditional XML approach, AnnotationConfigWebApplicationContext class can be used in Java EE web applications. Here is an example.
  • In Java Web Applications, Spring handles web requests using a DispatcherServlet, which delegates incoming requests to the appropriate controllers and translates request and response entities as needed.
  • A Java Web Application can have as many instances of the DispatcherServlet class as makes sense for a use case.
  • Each DispatcherServlet instance gets its own Application Contexts, which has references to the Web Application 's ServletContext and its own ServletConfig.
  • Because none of these DispatcherServlets can access the Application Context for any other DispatcherServlets, it is often desirable to share certain beans (such as business objects or data access objects) in a common Root Application Context.
  • Root Application Context, global to the entire Web Application, is the parent of all the Application Contexts (which are owned by DispatcherServlets) and is created using the ContextLoaderListener. Here is an example. 
  • Root Application Context too, has a reference to the Web Application's  ServletContext, but because it does not belong to any particular Servlet, it does not have a ServletConfig reference.
As a general rule, you should always have one Root Application Context from which all other Application Contexts inherit in one way or another.

ContextLoaderListener Details

Bootstrap listener to start up and shut down Spring's Root Application Context.
public ContextLoaderListener(WebApplicationContext context)

Create a new ContextLoaderListener with the given Application Context. This constructor is useful in Servlet 3.0+ environments where instance-based registration of listeners is possible through the ServletContext.addListener(java.lang.String) API.

context - the application context to manage

Also I will add a link to this blog post which is helpful. 
Also a stackoverflow link.
And here is a link to another great blog post.
And another stackoverflow link.