我们可以在 Spring 上执行 @Scheduled 并结合 cron 参数,强制在启动时执行第一次吗?

Can we make a @Scheduled execution on Spring, mixed with cron parameter, forcing a first execution at boot time?

我在互联网上搜索了很多关于 Baeldung here 提到的选项的信息,但我找不到任何示例。我想使用这样的东西:

@Scheduled(cron="@reboot")
@Scheduled(cron="0 0 5 * * *")
public void somethingToDoOnRebootTime() {
  // code here, to run every day at 5a.m., AND at boot first time... 
}

但它没有用,因为“@reboot”不是有效的 cron 表达式...我尝试将此“@reboot”用作该方法的普通注释,但它不存在也...

有人可以帮助我吗? Baeldung 上的文章有错吗?

基于@M.Deinum 评论...我使用了 ApplicationListener,但使用了 ApplicationReadyEvent!所以,我的例子变成了:

@EventListener(ApplicationReadyEvent.class)
@Scheduled(cron="0 0 5 * * *")
public void somethingToDoOnRebootTime() {
  // code here, to run every day at 5a.m., AND at boot first time... 
}