@Scheduled 运行 在 16:00

@Scheduled running at 16:00

我在SpringBoot中创建了这个方法

    @Scheduled(cron = "0 16 * * * *")
    public void sendMsg() {
}

每天16:00下午(中午)执行:

而是每天执行几次

我觉得你的表情应该是0 0 16 ? * * *

有许多在线 cron 计算器可用于计算表达式或创建表达式。

它应该是这样的:

@Scheduled(cron = "0 0 16 * * *")
    public void sendMsg() {
}

正如之前的回答所指出的,您的表达式是无效的“Spring 表达式”,而是 unix 表达式。 Spring 利用 Quartz-type 添加秒值作为第一个参数:

+-------------------- second (0 - 59)
|  +----------------- minute (0 - 59)
|  |  +-------------- hour (0 - 23)
|  |  |  +----------- day of month (1 - 31)
|  |  |  |  +-------- month (1 - 12)
|  |  |  |  |  +----- day of week (0 - 6) (Sunday=0 or 7)
|  |  |  |  |  |  +-- year [optional]
|  |  |  |  |  |  |
*  *  *  *  *  *  * command to be executed

Source