title: Spring autowire priority with more than two layers
body: <p>How am I able to override an autowired bean more than once? Consider this 3-layer construct:</p>
  
  <p><strong>Library 1</strong> defines an interface and a default implementation.</p>
  
  <pre><code>public interface Foo {}
  
  @Component
  public class FooImpl1 implements Foo {}
  </code></pre>
  
  <p>Throughout all 3 layers the interface will be used for autowiring.</p>
  
  <pre><code>@Autowired
  private Foo foo;
  </code></pre>
  
  <p><strong>Library 2</strong> depends on library 1 and provides its own implementation which has to override the first one, i.e. be autowired into existing code of library 1.</p>
  
  <pre><code>@Component
  public class FooImpl2 implements Foo {}
  </code></pre>
  
  <p>The actual <strong>application</strong> depends on library 2 and also provides another implementation that has to override the former one.</p>
  
  <pre><code>@Component
  public class FooImpl3 implements Foo {}
  </code></pre>
  
  <p><strong>How do I configure this?</strong> If there were only two layers, I could use <code>@Primary</code> but this doesn't work with more than two layers because <code>@Primary</code> can't be overriden again. Is there a more fine-grained way of prioritizing beans that I'm overlooking or can I accomplish a second override using a <code>@Configuration</code> or do you simply can not overide a bean more than once and I have to resort to some kind of static helper like <code>FooProvider.getFoo()</code> instead of autowiring?</p>