title: class required a single bean, but 2 were found:
body: <p>I have the below interface:</p>
  
  <pre><code>public interface MailSender {
      void sender(String to, String subject,String body);
  }
  </code></pre>
  
  <p>With 2 imlementation of it:</p>
  
  <pre><code>public class SmtpkMailSender implements MailSender   {
  
      static Log log=LogFactory.getLog(MailSender.class); 
  
      public void sender(String to, String subject,String body){
          log.info("SMTP To: "+to);
          log.info("SMTP Subjecy: "+subject);
          log.info("SMTP body: "+body);
      }
  
  }
  </code></pre>
  
  <p>and the second one is:</p>
  
  <pre><code>@Primary
  public class MockMailSender implements MailSender   {
  
      static Log log=LogFactory.getLog(MailSender.class); 
  
      public void sender(String to, String subject,String body){
          log.info("To: "+to);
          log.info("Subject: "+subject);
          log.info("body: "+body);
      }
  
  }
  </code></pre>
  
  <p>I used the dependency injection into the controller class which is as following:</p>
  
  <pre><code>@RestController
  public class MailController {
  
      @Autowired
      private MailSender smtpkMailSender;
  
      @RequestMapping("/send")
      public String send(){
          smtpkMailSender.sender("Person", "Important", "Take Care");
          return "mail is sent";
      }
  }
  </code></pre>
  
  <p>At the end i have a configuration class which contains my Beans:</p>
  
  <pre><code>@Configuration
  public class MailConfig {
  
      @Bean
      public SmtpkMailSender getSmtpkMailSender(){
          return new SmtpkMailSender();
      }
  
      @Bean
      public MockMailSender getMockMailSender(){
          return new MockMailSender();
      }
  
  }
  </code></pre>
  
  <p>Unfortunatly, when i run my application it complains with:</p>
  
  <pre><code>Description:
  
  Field smtpkMailSender in com.example.demo.MailController required a single bean, but 2 were found:
      - getSmtpkMailSender: defined by method 'getSmtpkMailSender' in class path resource [com/example/mail/MailConfig.class]
      - getMockMailSender: defined by method 'getMockMailSender' in class path resource [com/example/mail/MailConfig.class]
  
  
  Action:
  
  Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
  </code></pre>
  
  <p>As you see, although i have specified the <code>MockMailSender</code> as Primary the spring still complains, and cannot identify it</p>