【发布时间】:2020-10-14 23:36:48
【问题描述】:
我在互联网上多次搜索 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的文章是不是错了?
【问题讨论】:
-
创建一个
ApplicationListener,在偶数ContextRefreshedEvent时触发该方法。 -
差不多了,@M.Deinum!我使用 ApplicationListener 但使用 ApplicationReadyEvent!
-
您没有在问题中提到 Spring Boot,并且没有 Spring Boot,该事件不存在。
标签: spring cron scheduled-tasks spring-scheduled