title: getServletConfigClasses() vs getRootConfigClasses() when extending AbstractAnnotationConfigDispatcherServletInitializer
body: <p>What is the difference between <em><code>getServletConfigClasses()</code></em> vs  <em><code>getRootConfigClasses()</code></em> when extending <em><code>AbstractAnnotationConfigDispatcherServletInitializer</code></em>.
  I've been reading a lot sources since this morning but I haven't get any clear understanding on the differences yet :</p>
  
  <p>Please have look at these two configurations :</p>
  
  <p>1).</p>
  
  <pre><code>public class SpringMvcInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {         
          return new Class[] { ConServlet.class }; 
      }
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {                      
          return null;
      }
          ....
          ....    
          }
  </code></pre>
  
  <p>The <em><code>ConServlet.class</code></em> is refering to </p>
  
  <pre><code>@EnableWebMvc 
  @Configuration
  @ComponentScan({ "com" })
  @Import({ SecurityConfig.class })
  public class ConServlet {
      @Bean
      public InternalResourceViewResolver viewResolver() {
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
          viewResolver.setViewClass(JstlView.class);
          viewResolver.setPrefix("/WEB-INF/pages/");
          viewResolver.setSuffix(".jsp");
          return viewResolver;
      }   
  }
  </code></pre>
  
  <p>2). </p>
  
  <pre><code>public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return null;
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return new Class&lt;?&gt;[] { WebConfig.class }; 
      }
      .....
  }
  </code></pre>
  
  <p>the <em>WebConfig.class</em> is refering to </p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = { "....." })
  public class WebConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
      }
  
      @Bean
      public ViewResolver viewResolver() {
  
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
          viewResolver.setViewClass(JstlView.class);
          viewResolver.setPrefix("/WEB-INF/views");
          viewResolver.setSuffix(".jsp");
          return viewResolver;
      }
  }
  </code></pre>
  
  <p>I see both <em>ConServlet</em> &amp; <em>WebConfig</em> (more or less) doing the same things like initializating view :</p>
  
  <p>But why  :</p>
  
  <ul>
  <li><em>ConServlet</em> is returned in <em><code>getRootConfigClasses()</code></em></li>
  <li>while <em>WebConfig</em> is returned in <em><code>getServletConfigClasses()</code></em> </li>
  </ul>
  
  <p>I read the documentation </p>
  
  <p>both <em>getRootConfigClasses()</em> &amp; <em>getServletConfigClasses()</em>  is for</p>
  
  <blockquote>
    <p>Specify @Configuration and/or @Component classes to be provided to..
    (their differences )</p>
  </blockquote>
  
  <ul>
  <li><em>the root application context</em> for <em><code>getRootConfigClasses()</code></em></li>
  <li><em>the dispatcher servlet application context for</em> <em><code>getServletConfigClasses()</code></em> </li>
  </ul>
  
  <p>but why then <em>ConServlet</em> &amp; <em>WebConfig</em>  doing same things (like initizialising view), maybe I'm the one misunderstood it. What's are actually root context and dispatcher servlets (I know this one) in the <em>simple term/example</em></p>
  
  <p>Thank you!</p>