繁体   English   中英

spring 启动启动器 email null 指针异常

[英]spring boot starter email null pointer exception

我正在使用 spring 引导启动器依赖项发送一些电子邮件。 但它抛出NullPointerException 我尝试记录 email 对象并且它们可用。

这是github中的代码

这是 email 对象

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

这是错误日志: https://pastebin.com/QFLM9vwi

请从

@Autowired
private static JavaMailSender emailSender;

因为 static 成员不能自动装配。 此外,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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM