import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Component
@EnableScheduling // 1.开启定时任务,定时发送短信
public class ScheduledSendMessage {
//3.添加定时任务,测试
@Scheduled(cron = "0/5 * * * * ?")
private void configureTasks() {
System.err.println("执行静态定时任务时间: " + Tools.getTimestamp(null));
}
}
关于cron的工具
在线生成表达式(生成七位,可能复制进去启动会报错,可用下面链接查看执行结果,方便修改):https://cron.qqe2.com/
cron执行时间计算:https://tool.lu/crontab/