title: Spring Bean implementing multiple interfaces
body: <p>I have a bean which implements two interfaces. The barebones code is as follows:</p>
  
  <pre><code>interface InterfaceA {
    ...
  }
  
  interface InterfaceB {
    ...
  }
  
  public class ClassC implements InterfaceA, InterfaceB {
    ...
  }
  </code></pre>
  
  <p>In my AppConfig I am specifying the following:</p>
  
  <pre><code>@Bean(name = "InterfaceA")
  public InterfaceA interfaceA() {
      return new ClassC();
  }
  
  @Bean(name = "InterfaceB")
  public InterfaceB interfaceB() {
      return new ClassC();
  }
  </code></pre>
  
  <p>And I use it so:</p>
  
  <pre><code>public class MyClass {
  
      @Inject
      private final InterfaceA a;
  
      public MyClass(@Named("InterfaceA") InterfaceA a) {
          this.a = a;
      }
       ...
  }
  </code></pre>
  
  <p>However, Spring complains that:</p>
  
  <blockquote>
    <p>No qualifying bean of type
    [com.example.InterfaceA] is
    defined: expected single matching bean but found 2:
    InterfaceA, InterfaceB</p>
  </blockquote>
  
  <p>Similar question was asked and answered for EJB <a href="https://stackoverflow.com/q/13986223/341008" title="Can an EJB bean implement multiple interfaces?">here</a> but I could not find anything for Spring beans. Anybody know the reason?</p>
  
  <p>The workaround is to introduce a new interface which extends both <code>InterfaceA</code> and <code>InterfaceB</code> and then let <code>ClassC</code> implement that. However, I am loath to change my design because of framework constraints.</p>