title: How exactly are the root context and the dispatcher servlet context into a Spring MVC web application?
body: <p>I am studying <strong>Spring MVC</strong> and I have some doubt related</p>
  
  <p>So, I have this configuration class that configure my <strong>DispatcherServlet</strong> that handle the user requests:</p>
  
  <pre><code>public class MyWebAppInitializer implements WebApplicationInitializer {
  
      @Override
      public void onStartup(ServletContext container) {
  
          // Create the 'root' Spring application context
          AnnotationConfigWebApplicationContext rootContext = ...
          // Create the dispatcher servlet's Spring application context
          AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
  
         dispatcherContext.register(DispatcherConfig.class);
  
         // Register and map the dispatcher servlet
         ServletRegistration.Dynamic dispatcher = container.addServlet("main", new DispatcherServlet(dispatcherContext));
         dispatcher.setLoadOnStartup(1);
         dispatcher.addMapping("main/");
     }
  }
  </code></pre>
  
  <p>It is pretty clear for me how the <strong>DispatcherServlet</strong> works. My doubts are related to the <strong>context</strong> concept.</p>
  
  <p>1) What exactly represent a <strong>context</strong>? I think that is something like a set of beans that have a specific pourpose and that works togheter into an environment. But I am absolutly not true about this assertion.</p>
  
  <p>2) What is the difference between the <strong>root context</strong> and the <strong>dispatcher servlet context</strong>?</p>
  
  <p>3) From what I have understand the beans defined in <strong>dispatcherContext</strong> have access to beans defined in <strong>rootContext</strong> (but the opposite is not true). Why?</p>
  
  <p>Tnx</p>