簡體   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