参考网址:5分钟搞懂如何在Spring Boot中Schedule Tasks
从一个简单的Schedule开始
1、写测试类
@Scheduled(cron = "0/2 * * * * ?")
public void testB(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy MM dd || HH:mm::ss");
Date date = new Date();
System.out.println(sdf.format(date)+"@Scheduled工作了。。。");
};
2、Springboot启动类上增加@EnableScheduling注解
运行结果如下。。。