title: How do I extend a named Spring bean when using a @Qualifier specified bean injection point?
body: <p>How do I extend a named bean when using a <code>@Qualifier</code> specified bean injection point?</p>
  
  <p>I have project 1 consisting of 3 <a href="/questions/tagged/spring" class="post-tag" title="show questions tagged &#39;spring&#39;" rel="tag">spring</a> beans:</p>
  
  <pre><code>@Component("bean1")
  public class Bean1 implements Bean {
  }
  
  @Component("bean2")
  public class Bean2 implements Bean {
  }
  
  @Component("bean3")
  public class Bean3 {
      private Bean bean;
  
      public void setBean(@Qualifier("bean1") final Bean bean) {
          this.bean = bean;
      }
  }
  </code></pre>
  
  <p>This project is bundled into a jar and included as a dependency on my 2nd project:</p>
  
  <pre><code>@Component("bean1")
  @Primary
  public class Bean1Child extends Bean1 {
  }
  </code></pre>
  
  <p>What I want to happen is for the bean, <code>Bean1Child</code>, to be injected into <code>Bean3</code>'s setter method. Unfortunatly I am receiving an error.</p>
  
  <blockquote>
    <p>org.springframework.context.annotation.ConflictingBeanDefinitionException:
    Annotation-specified bean name 'bean1' for bean class [Bean1Child]
    conflicts with existing, non-compatible bean definition of same name
    and class [Bean1]</p>
  </blockquote>
  
  <p>I needed to use <code>@Qualifier</code> so that <code>Bean2</code> is not injected into <code>Bean3</code>  Using the <code>@Primary</code> annotation did not help. How can I have <code>Bean1Child</code> injected into <code>Bean3</code> when running from my 2nd project?</p>