使用Spring调度程序在每天上午12:00运行Cron

使用Spring调度程序在每天上午12:00运行Cron,spring,cron,cronexpression,spring-scheduled,Spring,Cron,Cronexpression,Spring Scheduled,我每天都在尝试执行一个方法,我使用Spring为它添加了调度程序,但它没有被执行 <task:scheduled-tasks scheduler="myScheduler"> <task:scheduled ref="logDeletionTask" method="deleteExpiredLogs" cron="0 0 0 * * ?" /> </task:scheduled-tasks> <task:scheduler pool-size=

我每天都在尝试执行一个方法,我使用Spring为它添加了调度程序,但它没有被执行

<task:scheduled-tasks scheduler="myScheduler">
    <task:scheduled ref="logDeletionTask" method="deleteExpiredLogs" cron="0 0 0 * * ?" />
</task:scheduled-tasks>
<task:scheduler pool-size="25" id="myScheduler"/>

对我来说,您要寻找的cron表达式是:
012**?

以下是一个工作示例:

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">

    <bean id="logDeletionTask" class="task.Task" />

    <task:scheduled-tasks scheduler="myScheduler">
        <task:scheduled ref="logDeletionTask" method="deleteExpiredLogs" cron="0 0 12 * * ?" />
    </task:scheduled-tasks>

    <task:scheduler pool-size="25" id="myScheduler"/>
</beans>

我想这个表达式会将作业安排在中午12点。表达式的第三部分是小时,应该是0到23点(0表示中午12点)。如果您希望作业在中午12点触发,正确的表达式是
0 0**?
如果您希望作业在凌晨12点触发,则答案是
0 0 12**?
如果0对应于下午12点,那么1对应于下午1点,13对应于凌晨1点,则任何人都无法接受,可能您正在运行代码具有不同时区的计算机或服务器
package task;

import java.util.Date;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Task {

    public static void main(String[] args) throws InterruptedException {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        while (true) {
            Thread.sleep(1000);
        }
    }

    public void deleteExpiredLogs() {
        System.out.println(new Date());
    }
}