1.在线Cron表达式生成器网址
https://cron.qqe2.com/
2.定义scheduled
@Component
public class HelloJob{
@Autowired
private HelloService helloService;
@Scheduled(cron = "0/5 * * * * ?")
public void autoClose(){
helloService.closeJob();
System.out.println("定时调用,关闭执行service中方法");
}
}
3.在springboot启动类开启定时任务
@EnableScheduling
public class Application{
public static void main(String [] args){
SpringApplication.run(Application.class,args);
}
}