No Data

springboot3定时任务cron表达式

原创  作者:斩雪碎光阴  发布于:2023年11月02日  阅读量:267
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
  分类:  标签:

cron表达式生成:

https://cron.qqe2.com/

package com.xxx.task;


import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;


@Component
@Configurable
@EnableScheduling
public class TimingTask {
    @Scheduled(cron = "0 0 0/1 * * ? ")
    public void reportCurrentByCron(){
        System.out.println ("执行:" + dateFormat ().format(new Date()));
    }
    private SimpleDateFormat dateFormat(){
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }
}


相关文章