Could not autowire. No beans of 'JavaMailSender' type found.
- 导入依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId><version>2.1.5.RELEASE</version>
</dependency>
- 配置邮箱相关参数
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
- 使用
原因:爆红提示找不到Could not autowire. No beans of 'JavaMailSender' type found.
,原因是邮箱配置参数找不到
解决:将邮箱配置参数迁移至 resource
中 的配置文件中。