title: @ComponentScan from 2 packages
body: <p>I have 2 projects, the main spring boot project and the second spring project, which contains @Contollers, @Services and so on.</p>
  
  <p>I try to use some of this services in main project. I saw similar questions like <a href="https://stackoverflow.com/questions/12207057/how-to-load-all-beans-lazily-with-componentscan-in-spring">here</a>, <a href="https://stackoverflow.com/questions/30970748/multiple-componentscan-in-spring-4">here</a>, <a href="https://stackoverflow.com/questions/16238089/filter-specific-packages-in-componentscan">here</a> and many others, but it does not work for me</p>
  
  <p>1) if I have just </p>
  
  <pre><code>@SpringBootApplication
  public class App { ... }
  </code></pre>
  
  <p>then it does not compile because can not find services from the second project</p>
  
  <p>2) if I try to scan the second package</p>
  
  <pre><code>@SpringBootApplication
  @ComponentScan("secondPackage")
  public class App {}
  </code></pre>
  
  <p>then the application starts without errors, but controller mapping does not work at all. Mapping from both projects can not be resolved.</p>
  
  <p>3) then I tried exclude controllers from second package, because I do not need them, mapping still does not work</p>
  
  <pre><code>@ComponentScan(basePackages="secondPackage", excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = Controller.class)})
  </code></pre>
  
  <p>4) then I tried to scan for particular services, but in this case other resources are not available and I have to include to much paths</p>
  
  <pre><code>@ComponentScan({"first package", "second package"})
  </code></pre>
  
  <p>5) finally I tried to make 2 configuration files </p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages = {"mainPackage"})
  public class MainConfiguration {
  
  }
  
  @Configuration
  @ComponentScan(basePackages="secondPackage", 
          excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = Controller.class)})
  public class SecondConfiguration {
  
  }
  </code></pre>
  
  <p>but I did not found example, how I can prepare context before SpringApplication.run(App.class, args); and then make the app run with my context. like </p>
  
  <pre><code>ApplicationContext myContext = new AnnotationConfigApplicationContext(OrderStatusConfiguration.class, ShopRuServicesConfiguration.class);
  SpringApplication.run(App.class, myContext, args);
  </code></pre>
  
  <p>So please give me an advice, why mapping does not work or how should I proper autowire services from the second project!</p>
  
  <p>I appreciate any help! Thanks!</p>