@Component
public class SaveProviderStartupRunner implements ApplicationRunner {
@Autowired
private ProviderController providerController;
@Autowired
private AttachmentEmail attachmentEmail;
String fileDate1 = new SimpleDateFormat("dd.MM.yyyy").format(new Date());
LocalDate today = LocalDate.now();
String fileDate = (today.minusDays(1)).format(DateTimeFormatter.ofPattern("dd MMM"));
String fileDate2 = (today.minusMonths(1)).format(DateTimeFormatter.ofPattern("MMM"));
@Override
public void run(ApplicationArguments args) throws Exception {
providerController.saveCards();
}
//@Override
@Scheduled(cron = "26 17 * * * *")
public void run1(ApplicationArguments args) throws Exception {
attachmentEmail.sendMail1("[email protected]", "[email protected]", "List for " fileDate, " ", "Report " fileDate1 ".xlsx");
attachmentEmail.sendMail2("[email protected]", "[email protected]", "List for " fileDate, " ", "Report1 " fileDate1 ".xlsx");
attachmentEmail.sendMail3("[email protected]", "[email protected]", "List for " fileDate, " ", "Report2 " fileDate1 ".xlsx");
}
@Scheduled(cron = "27 17 * * * *")
public void run2(ApplicationArguments args) throws Exception {
attachmentEmail.sendMail4("[email protected]", "[email protected]", "List for " fileDate, " ", "Report3 " fileDate1 ".xlsx");
attachmentEmail.sendMail5("[email protected]", "[email protected]", "List for " fileDate, " ", "Report4 " fileDate1 ".xlsx");
attachmentEmail.sendMail6("[email protected]", "[email protected]", "List for " fileDate, " ", "Report5 " fileDate1 ".xlsx");
}
@Scheduled(cron = "28 17 * * * *")
public void run3(ApplicationArguments args) throws Exception {
attachmentEmail.sendMail7("[email protected]", "[email protected]", "List for " fileDate, " ", "Report6 " fileDate1 ".xlsx");
attachmentEmail.sendMail8("[email protected]", "[email protected]", "List for " fileDate, " ", "Report7 " fileDate1 ".xlsx");
attachmentEmail.sendMail9("[email protected]", "[email protected]", "List for " fileDate, " ", "Report8 " fileDate1 ".xlsx");
}
}
我的專案有一種方法可以開始保存到 .xlsx 檔案。首先,我想將它們分開,以便一次保存一些檔案,另一次保存其他檔案。我嘗試設定此方法以通過 Scheduled 運行
@Override
@Scheduled(cron = "10 10 * * * *")
public void run(ApplicationArguments args) throws Exception {
providerController.saveCards();
}
但是,我得到一個錯誤,因為在我有(args)的方法的引數中,沒有它這個方法不起作用。如何設定調度程式以便按時呼叫我的方法?
uj5u.com熱心網友回復:
On run1(),run2()并且run3()您不需要 ,ApplicationArguments args因為唯一的方法實際上覆寫了ApplicationRunner.run(ApplicationArguments args)方法,因此只需洗掉它們。此外,我會保持簡單并簡單地將方法分開(一個覆寫ApplicationRunner.run(ApplicationArguments args)方法和一個被調度的方法):
@Component
public class SaveProviderStartupRunner implements ApplicationRunner {
@Autowired
private ProviderController providerController;
@Autowired
private AttachmentEmail attachmentEmail;
String fileDate1 = new SimpleDateFormat("dd.MM.yyyy").format(new Date());
LocalDate today = LocalDate.now();
String fileDate = (today.minusDays(1)).format(DateTimeFormatter.ofPattern("dd MMM"));
String fileDate2 = (today.minusMonths(1)).format(DateTimeFormatter.ofPattern("MMM"));
@Override
public void run(ApplicationArguments args) throws Exception {
providerController.saveCards();
}
@Scheduled(cron = "10 10 * * * *")
public void run() throws Exception {
providerController.saveCards();
}
@Scheduled(cron = "26 17 * * * *")
public void run1() throws Exception {
attachmentEmail.sendMail1("[email protected]", "[email protected]", "List for " fileDate, " ", "Report " fileDate1 ".xlsx");
attachmentEmail.sendMail2("[email protected]", "[email protected]", "List for " fileDate, " ", "Report1 " fileDate1 ".xlsx");
attachmentEmail.sendMail3("[email protected]", "[email protected]", "List for " fileDate, " ", "Report2 " fileDate1 ".xlsx");
}
@Scheduled(cron = "27 17 * * * *")
public void run2() throws Exception {
attachmentEmail.sendMail4("[email protected]", "[email protected]", "List for " fileDate, " ", "Report3 " fileDate1 ".xlsx");
attachmentEmail.sendMail5("[email protected]", "[email protected]", "List for " fileDate, " ", "Report4 " fileDate1 ".xlsx");
attachmentEmail.sendMail6("[email protected]", "[email protected]", "List for " fileDate, " ", "Report5 " fileDate1 ".xlsx");
}
@Scheduled(cron = "28 17 * * * *")
public void run3() throws Exception {
attachmentEmail.sendMail7("[email protected]", "[email protected]", "List for " fileDate, " ", "Report6 " fileDate1 ".xlsx");
attachmentEmail.sendMail8("[email protected]", "[email protected]", "List for " fileDate, " ", "Report7 " fileDate1 ".xlsx");
attachmentEmail.sendMail9("[email protected]", "[email protected]", "List for " fileDate, " ", "Report8 " fileDate1 ".xlsx");
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/395182.html
上一篇:什么是光纖?光纖的原理是什么?你能想象沒有光纖通訊的世界么?
下一篇:CGB2111筆記的鏈接大全
