title: What is the use case of @Import annotation?
body: <p>According to <a href="http://docs.spring.io/autorepo/docs/spring/4.1.1.RELEASE/javadoc-api/org/springframework/context/annotation/Configuration.html" rel="noreferrer">official doc</a>:</p>
  <blockquote>
  <p>Annotation Type Configuration</p>
  <p>Indicates that a class declares one or more @Bean methods and may be
  processed by the Spring container to generate bean definitions...</p>
  <p>@Configuration classes may be composed using the @Import annotation,
  not unlike the way that  works in Spring XML. Because
  @Configuration objects are managed as Spring beans within the
  container..</p>
  </blockquote>
  <p>But i can also use @Configuration annotation without @Import. I have tested the code listed below and it works as expected. So what is the purpose to use @Import?</p>
  <p><strong>DispatcherServletInitializer</strong></p>
  <pre><code>public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class&lt;?&gt;[] { WebConfig.class };
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return null;
      }
  
      @Override
      protected String[] getServletMappings() {
          return new String[] { &quot;/&quot; };
      }
      
   }
  </code></pre>
  <p><strong>WebMvcConfigurerAdapter</strong></p>
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = { &quot;package.name&quot; })
  // @Import(OptionalConfig.class) 
  public class WebConfig extends WebMvcConfigurerAdapter {
      // ...
  }
  </code></pre>
  <p><strong>OptionalConfig</strong></p>
  <pre><code>@Configuration
  public class OptionalConfig {
      
      @Bean(name = &quot;myClass&quot;)
      public MyClass myClass() {
          return new MyClass();
      }
  }
  </code></pre>
  <p><strong>Service</strong></p>
  <pre><code>@Service
  public class MyServiceImpl implements MyService {
      
      @Autowired
      private MyClass myClass;    // yes, it works
  
      // ...
  }
  </code></pre>