title: Could not autowire org.springframework.mail.javamail.JavaMailSender
body: <p>I got the following problem when trying to run my application. Have debugged everything and still nothing.</p>
  
  <p>The IDE is finding the bean without any issue so I'm very confused as to what is happening here.</p>
  
  <pre><code>SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailManager': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.testmail.app.service.implement.CustomMManagerService.setMailSender(org.springframework.mail.javamail.JavaMailSender); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.mail.javamail.JavaMailSender] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
  </code></pre>
  
  <p>My bean generation is located in following file:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = "com.testmail.app")
  public class WebConfig extends WebMvcConfigurerAdapter {
   //CODE CODE CODE
  
      @Bean
      public JavaMailSenderImpl mailSender() {
          JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
  
          javaMailSender.setProtocol("SMTP");
          javaMailSender.setHost("127.0.0.1");
          javaMailSender.setPort(25);
  
          return javaMailSender;
      }
  
  // CODE CODE CODE
  }
  </code></pre>
  
  <p>Code for CustomMManager:</p>
  
  <pre><code>public interface CustomMManager extends Serializable {
      void sendMail(String mailFrom,String mailTo,String subject,String mailBody);
  }
  </code></pre>
  
  <p>Finally the code for CustomMManagerService:</p>
  
  <pre><code>@Service("mailManager")
  public class CustomMManagerService implements CustomMManager {
      private JavaMailSender mailSender;
  
      @Autowired
      public void setMailSender(JavaMailSender mailSender) {
          this.mailSender = mailSender;
      }
  
      @Override
      public void sendMail(final String mailFrom, final String mailTo, final String subject, final String mailBody) {
          try {
              mailSender.send(new MimeMessagePreparator() {
                  public void prepare(MimeMessage mimeMessage)
                          throws Exception {
                      MimeMessageHelper message = new MimeMessageHelper(mimeMessage,
                              false, "UTF-8");
                      message.setFrom(mailFrom);
                      message.addTo(mailTo);
                      message.setSubject(subject);
                      message.setText(mailBody, true);
                  }
              });
          } catch (MailSendException e) {
              // your codes;
          }
      }
  }
  </code></pre>
  
  <p>Help is really appreciated.</p>