【定时任务】
1.启动总开关
@EnableScheduling加在@SpringBootApplication注解的start入口处,表示启动总开关
@SpringBootApplication@EnableSchedulingpublic 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表达式,秒分时天等等,具体用到可以再百度