Could not autowire. No beans of 'JavaMailSender' type found..md

Scroll Down

Could not autowire. No beans of 'JavaMailSender' type found.

  1. 导入依赖
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-mail</artifactId>
   <version>2.1.5.RELEASE</version>
</dependency>
  1. 配置邮箱相关参数
mail.address = xxx@chinamobile.com
mail.receiver = xxx@126.com
spring.mail.host=smtp.chinamobile.com
spring.mail.username=xxx@chinamobile.com
spring.mail.password=xxx
spring.mail.default-encoding=UTF-8
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=false
spring.mail.properties.mail.smtp.starttls.required=false
  1. 使用

image.png
原因:爆红提示找不到Could not autowire. No beans of 'JavaMailSender' type found.,原因是邮箱配置参数找不到
image.png
解决:将邮箱配置参数迁移至 resource中 的配置文件中。
image.png
image.png