spring 引导启动器电子邮件空指针异常
spring boot starter email null pointer exception
我正在使用 spring 引导启动器依赖项来发送一些电子邮件。但它抛出 NullPointerException
。我尝试记录电子邮件对象,它们可用。
这是github
中的代码
这是电子邮件对象
claudia.prescott@mail.com
SimpleMailMessage: from=Sustainable Educational Foundation - SEF; replyTo=null; to=claudia.prescott@mail.com; cc=; bcc=; sentDate=null; subject=APPROVED; text=MENTEE_SELECTION
dave.walters3@protonmail.com
SimpleMailMessage: from=Sustainable Educational Foundation - SEF; replyTo=null; to=dave.walters3@protonmail.com; cc=; bcc=; sentDate=null; subject=PENDING; text=MENTEE_SELECTION
michele.moore3@protonmail.com
请从
移除静电
@Autowired
private static JavaMailSender emailSender;
因为静态成员不能自动装配。此外,EmailUtil 不是 spring bean,因此自动装配将不起作用。
已更新:
电子邮件实用工具:
@Component
public class EmailUtil {
@Autowired
private JavaMailSender emailSender;
程序服务:
@Service
public class ProgramService {
@Autowired
private EmailUtil emailUtil
......
public Program updateState(long id) throws ResourceNotFoundException {
emailUtil.sendSimpleMessage(email);
我正在使用 spring 引导启动器依赖项来发送一些电子邮件。但它抛出 NullPointerException
。我尝试记录电子邮件对象,它们可用。
这是github
中的代码这是电子邮件对象
claudia.prescott@mail.com
SimpleMailMessage: from=Sustainable Educational Foundation - SEF; replyTo=null; to=claudia.prescott@mail.com; cc=; bcc=; sentDate=null; subject=APPROVED; text=MENTEE_SELECTION
dave.walters3@protonmail.com
SimpleMailMessage: from=Sustainable Educational Foundation - SEF; replyTo=null; to=dave.walters3@protonmail.com; cc=; bcc=; sentDate=null; subject=PENDING; text=MENTEE_SELECTION
michele.moore3@protonmail.com
请从
移除静电@Autowired
private static JavaMailSender emailSender;
因为静态成员不能自动装配。此外,EmailUtil 不是 spring bean,因此自动装配将不起作用。
已更新:
电子邮件实用工具:
@Component
public class EmailUtil {
@Autowired
private JavaMailSender emailSender;
程序服务:
@Service
public class ProgramService {
@Autowired
private EmailUtil emailUtil
......
public Program updateState(long id) throws ResourceNotFoundException {
emailUtil.sendSimpleMessage(email);