title: How do you override a spring bean defined in xml using Annotations?
body: <p>I have an existing bean <code>overrideBean</code> defined in <code>spring.xml</code> which I would like to override using annotations.  I have tried the following to override the bean:</p>
  
  <pre><code>@Configuration
  @ImportResource({"/spring.xml"})
  public class Main {
  
      public static void main(String[] args) {
          AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DdwMain.class);
  
          Object o = context.getBean("overrideBean");
          // o should be null but it is not
      }
  
      @Bean(name="overrideBean")
      public OverrideBean overrideBean() {
          return null;
      }
  
  }
  </code></pre>
  
  <p>Using the above code the bean from the <code>spring.xml</code> config is always instantiated and returned by the <code>context.getBean</code> call.  </p>
  
  <p>The bean can be overridden by including another XML config file in the <code>@ImportResource</code> however I would prefer to find a solution using annotations would be cleaner.  </p>