title: Spring: Properly setup @ComponentScan
body: <p>I have following set up for my <code>Spring Application Context</code>.</p>
  
  <p><pre><code>
  @Configuration
  public class RmiContext {
  @Bean
      public RmiProxyFactoryBean service() {
          RmiProxyFactoryBean rmiProxy = new RmiProxyFactoryBean();
          rmiProxy.setServiceUrl("rmi://127.0.1.1:1099/Service");
          rmiProxy.setServiceInterface(Service.class);
          return rmiProxy;
      }
  }
  </pre></code></p>
  
  <p><pre><code>
  @Configuration
  public class LocalContext {
  @Bean
      public Controller Controller() {
          return new ControllerImpl();
      }
  }
  </pre></code></p>
  
  <p><pre><code>
  @Configuration
  @Import({RmiContext.class, LocalContext.class})
  public class MainContext {</p>
  
  <p>}
  </pre></code></p>
  
  <p>The above setup works fine, but I want to enable <code>@ComponentScan</code> annotating <code>Controller</code>s with <code>@Component</code> as there are many <code>Controller</code>s in my application which is tedious when declared one by one using <code>@Bean</code>.</p>
  
  <p><pre><code>
  @Configuration
  @ComponentScan(basePackageClasses = {Controller.class})
  public class LocalContext {
      /* ... */
  }
  </pre></code>
  The problem is that when I do <code>@ComponentScan(basePackageClasses = {Controller.class})</code>, the previously fine working <code>RmiProxyFactoryBean</code> are not recognized or can't be created.</p>
  
  <p>So, How do I configure my <code>MainContext</code> so that both beans via RMI and local beans are created?</p>