编译失败:Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘emailController’: Unsatisfied dependency expressed through field ‘mailSender’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘org.springframework.mail.javamail.JavaMailSender’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
解决方法:
编写配置文件
例子:
#debug: true
spring:
# 邮箱发送配置
mail:
# host不配置会注入失败
host: smtp.163.com
username: yu742139017@163.com
password: yuzhenhan123
default-encoding: utf-8
protocol: smtp
properties:
mail:
smtp:
connectiontimeout: 5000
timeout: 3000
writetimeout: 5000