【定时任务】
1.给start方法添加定时总开关
@EnableScheduling加在@SpringBootApplication注解的start入口处,表示启动总开关

@SpringBootApplication
@EnableScheduling
public class start {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(start.class, args);
    }
}

2.再单独给方法加配置
@Scheduled(cron=”0/5 * * * * ?”)每5秒打印当前时间

    @Scheduled(cron="0/5 * * * * ?")
    public void reportCurrentTime() {
        log.info("The time is now {}", dateFormat.format(new Date()));
    }

备注:cron表达式,秒分时天等等,具体用到可以再百度

版权声明:本文为likailun原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/likailun/p/9323558.html