定时任务还不会嘛,没关系!花5秒钟就会写~~
两个类两个注解搞定会玩
TaskScheduler -->任务调度者
TaskExecutor -->任务执行者
@EnableScheduling
@SpringBootApplication
@EnableScheduling
public class SpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}
如图
@Scheduled(cron = "0/2 * * * * ?")
@Service
public class SchedulingConfig {
//(cron = "0/2 * * * * ?") cron表达式格式 “秒 分 时 日 月 年 周几 年”
@Scheduled(cron = "0/2 * * * * ?")
public void scheduling(){
System.out.println("你被执行了!!");
}
}