【定時任務】
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表達式,秒分時天等等,具體用到可以再百度