I got the following problem when trying to run my application. Have debugged everything and still nothing.
The IDE is finding the bean without any issue so I\'m very con
In my case, I removed something and my project not shown as maven project. (I am using IntelliJ for my Spring Boot application)
Set project as maven project (Close and reopen IntelliJ. It will show popup) fixes the issue.
You may have forgotten to set the following properties:
spring.mail.host
spring.mail.username
spring.mail.password
spring.mail.port
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.
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
check application.properties config, such as:
spring.mail.host=smtp.xxx.com
spring.mail.username=xxx@xxx.com
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
Have you tried to declare your bean returning the interface implemented? Something like this:
@Bean
public JavaMailSender mailSender() {