春天cron表达每天1:01:am [英] Spring cron expression for every day 1:01:am
问题描述
我试图让我的代码执行一个固定的时间表,基于Spring cron表达式。我想让代码每天在1:01:am执行。我试过下面的表达式,但这并没有为我开火。这里的语法有什么问题?
I'm trying to have my code execute on a fixed schedule, based on a Spring cron expression. I would like the code to be executed every day at 1:01:am. I tried the following expression, but this didn't fire up for me. What's wrong with the syntax here?
@Scheduled(cron = "0 1 1 ? * *")
public void resetCache() {
// ...
}
推荐答案
尝试:
@Scheduled(cron = "0 1 1 * * ?")
下面你可以找到在春季论坛上找到的示例模式:
Below you can find example pattern found on spring forum:
* "0 0 * * * *" = the top of every hour of every day.
* "*/10 * * * * *" = every ten seconds.
* "0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day.
* "0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30 and 10 o'clock every day.
* "0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays
* "0 0 0 25 12 ?" = every Christmas Day at midnight
Cron表达式由六个字段表示:
Cron expression is represented by six fields:
second, minute, hour, day of month, month, day(s) of week
(*)
表示匹配任何
* / X
表示每个X
无特定值) - 当您需要在允许字符的两个字段之一中指定某个内容时有用,而不是其他字符。例如,如果我想让我的触发器在一个月的某一天(例如,10日)触发,但不关心一周中的哪一天发生,我会在个字段,?
?
("no specific value") - useful when you need to specify something in one of the two fields in which the character is allowed, but not the other. For example, if I want my trigger to fire on a particular day of the month (say, the 10th), but don't care what day of the week that happens to be, I would put "10" in the day-of-month field, and "?" in the day-of-week field.
PS:为了使其正常工作,请记住在您的应用程序上下文中启用它:http://docs.spring.io/autorepo/docs/ spring-framework / current / spring-framework-reference / html / scheduling.html#scheduling-annotation-support
PS: in order to make it works, remember to enable it in your application context: http://docs.spring.io/autorepo/docs/spring-framework/current/spring-framework-reference/html/scheduling.html#scheduling-annotation-support
这篇关于春天cron表达每天1:01:am的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!