java Spring 每 15 分钟执行一次方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28819560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring execute method every 15 minutes
提问by Bla Bla
I tried to use cron expression from this site http://www.cronmaker.com/
我试图从这个网站http://www.cronmaker.com/使用 cron 表达式
@Scheduled(cron = "0 0/15 * 1/1 * ? *")
public void clearRps() {
}
But it throws by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'clearRps': Cron expression must consist of 6 fields (found 7 in "0 0/15 * 1/1 * ? *")
但它抛出: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'clearRps': Cron expression must include 6 fields (found 7 in "0 0/15 * 1/1 * ? *")
回答by Rohit Jain
Just use the following cron:
只需使用以下 cron:
@Scheduled(cron = "0 0/15 * * * *")
Spring cron expression syntax slightly differs from unix cron expression. One immediate difference - it supports 1 less field (6 rather than 7).
Spring cron 表达式语法与 unix cron 表达式略有不同。一个直接的区别 - 它支持少 1 个字段(6 个而不是 7 个)。