一、启动类开启task注解
//springTask定时任务开启
@EnableScheduling
@SpringBootApplication
@MapperScan("com.zhenghe.mapper")
public class ZhengheApplication {
public static void main(String[] args) {
SpringApplication.run(ZhengheApplication.class,args);
}
}
二、编写实际要执行的定时任务
@Component
public class TestTask {
@Scheduled(cron = "0/5 * * * * *")
private void test(){
//这里是要写实际执行的定时任务业务
System.out.println("定时任务开启:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
}
}
三、启动测试
标签:springboot,springTask,public,整合,new,定时,class From: https://www.cnblogs.com/wlfs000000/p/17378655.html