title: How to override an imported resource using Spring @Configuration?
body: <p>Is it possible to override imported resources using Spring annotation configuration?</p>
  
  <p><strong>The configuration class:</strong></p>
  
  <pre><code>@Configuration
  @ImportResource({"classpath:applicationContext.xml"})
  public class CoreConfiguration {
  
      @Resource(name = "classA")
      private ClassA classA;
  
      @Bean(name = "nameIWantToOverride")
      private ClassB classB() {
         return new ClassB("different setting");
      }
  
  }
  </code></pre>
  
  <p><strong>The applicationContext.xml includes:</strong></p>
  
  <pre><code>&lt;bean name="classA" class="a.b.c.ClassA"&gt;
       &lt;property name="nameIWantToOverride" ref="classB" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>If classA has a classB field but I want it to use the ClassB I define in my configuration class, is that possible? I tried switching the order but that didn't help. It seems XML takes precedence as when I run a simple test of instantiating the config, it never reaches the classB method. If I change the name so it doesn't match the bean in the xml file, then it does reach the classB method.</p>
  
  <p>I've seen where it can work the other way: <a href="https://stackoverflow.com/questions/4943475/can-spring-framework-override-annotation-based-configuration-with-xml-based-conf">Can spring framework override Annotation-based configuration with XML-based configuration?</a> but what about this direction? Since this is the newer way of doing things, I would think it you'd be able to do this.</p>
  
  <p>What can I do to resolve this?</p>
  
  <p>Edit: Updated with XML. Assume classA has multiple fields but I just want to replace the one. </p>