title: Override bean definition doesn't work as expected
body: <p>I'm confused by Spring's annotation based configuration.</p>
  
  <p>I have an interface MyInterface and two classes (MyClass1 and MyClass2) which implement this interface.</p>
  
  <pre><code>@Component("MyInterface")
  public class MyClass1 implements MyInterface {
  
      public void execute() {
          System.out.println("MyClass1 executed");
      }
  }
  
  public class MyClass2 implements MyInterface {
  
      public void execute() {
          System.out.println("MyClass2 executed");
      }
  }
  </code></pre>
  
  <p>MyClass1 is created by using Component-Scan, MyClass2 is defined as a bean:</p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackageClasses = MyClass1Configuration.class)
  public class MyClass1Configuration {
  
  }
  
  @Configuration
  public class MyClass2Configuration {
  
      @Bean(name = "MyInterface")
      public MyInterface myClass2() {
          return new MyClass2();
      }
  }
  </code></pre>
  
  <p>I build the application context by using Spring Test's ContextConfiguration annotation:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = {MyClass1Configuration.class, MyClass2Configuration.class})
  public class SpringTestCase1 {
  
      @Autowired
      private MyInterface myInterface;
  
      @Test
      public void testMethod() {
          System.out.println("testMethod invoked");
          Assert.assertEquals(MyClass2.class, myInterface.getClass());
          myInterface.execute();
      }
  }
  </code></pre>
  
  <p>Unfortunately the test failes as Class1 is autowired instead of Class2. The expected behaviour is that MyClass2Configuration overrides beans which are defined by MyClass1Configuration. What's my fault.</p>
  
  <p>I created this example at GitHub, if you would like to take a look at a working example:
  <a href="https://github.com/OLibutzki/spring-test-configuration/tree/master/simple-sprint-test" rel="nofollow">https://github.com/OLibutzki/spring-test-configuration/tree/master/simple-sprint-test</a></p>
  
  <p>Thanks for your help.</p>
  
  <p>Kind regards
  Oliver</p>