Could not autowire org.springframework.mail.javamail.JavaMailSender
to create Bean don't forgot to specify mail properties, with Java class or in application.properties file, exemple
# configuration email
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=email
spring.mail.password=password
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
You may have forgotten to set the following properties:
spring.mail.host
spring.mail.username
spring.mail.password
spring.mail.port
check application.properties config, such as:
spring.mail.host=smtp.xxx.com [email protected] spring.mail.password=xxxxx spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true spring.mail.properties.mail.smtp.starttls.required=true
if you use spring-boot,can check should use @EnableAutoConfiguration this annotation
As per comment from mserioli the answer is that the bean must be declared in the configuration file being called at root.
In this case: Move
@Bean
public JavaMailSenderImpl mailSender()
to
public class ExtraConfig {
@Bean
public JavaMailSenderImpl mailSender() {
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setProtocol("SMTP");
javaMailSender.setHost("127.0.0.1");
javaMailSender.setPort(25);
return javaMailSender;
}
}
which is called in:
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[]{ExtraConfig.class};
}
Thus solving the problem. Thanks guys for assistance.