Я пытаюсь использовать MailSender в моем ApplicationListener, автоматически подключая его SpringContext:
package example.util.emailUtil;
@Component
public class PostUserListener implements ApplicationListener<OnPostUserDataEvent> {
@Autowired
private MailSender mailSender;
}
Класс конфигурации:
@ComponentScan(basePackages ={"example.util.emailUtil","example.model","example.service"})
@Configuration
public class MailProvider {
@Bean(name = "mailSender")
public MailSender javaMailService()
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setHost("smtp.gmail.com");
javaMailSender.setPort(587);
javaMailSender.setProtocol("smtp");
javaMailSender.setUsername("sender’s email");
javaMailSender.setPassword("sender’s password");
Properties mailProperties = new Properties();
mailProperties.put("mail.smtp.auth", "true");
mailProperties.put("mail.smtp.starttls.enable", "true");
mailProperties.put("mail.smtp.debug", "true");
javaMailSender.setJavaMailProperties(mailProperties);
return javaMailSender;
}
}
Но я улавливаю следующее исключение:
NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.mail.MailSender' available: expected at least 1 bean which qualifies as autowire candidat