title: Spring Dependency injection using interface with more than one implementation
body: <p>My question has already been asked here in the following link.</p>
  
  <p><a href="https://stackoverflow.com/questions/12899372/spring-why-do-we-autowire-the-interface-and-not-the-implemented-class/12899432#12899432">Spring: Why do we autowire the interface and not the implemented class?</a></p>
  
  <p>What I want to know if we use <code>@Qualifier</code> to inject a bean than what is the purpose of autowiring an interface ?? Why not we auto-wire the same implementation class ??</p>
  
  <p>By autowiring an interface we want to take advantage of run-time polymorphism but that's not achieved if we follow the approach of <code>@Qualifier</code>. Please suggest me a standard way.</p>
  
  <p>Following is the simple code if I do it without spring. I wonder how spring will inject the PrepaidPaymentService instance and PostPaidPaymentService instance??    </p>
  
  <pre><code> public interface PaymentService{
          public void processPayment();
      }
  
  
  
  public class PrepaidPaymentService implements PaymentService{
  
      public void processPayment(){
  
          System.out.println("Its Prepaid Payment Service");
  
      }
  }
  
  
  public class PostPaidPaymentService implements PaymentService{
  
      public void processPayment(){
  
           System.out.println("Its Postpaid Payment Service");
  
      }
  }
  
  
  public class Test {
  
  
      public PaymentService service;
  
      public static void main(String[] args) {
  
          Test test = new Test();
  
  
          int i = 1;
          if(i ==1 ){
              test.setService(new PrepaidPaymentService());
              test.service.processPayment();
          }
          i = 2;
          if(i == 2){
              test.setService(new PostPaidPaymentService()); 
              test.service.processPayment();
          }
  
  
      }
  
  
      public void setService(PaymentService service){
          this.service = service;
      }
  
  }
  </code></pre>