方法很简单首先写一个类
@Slf4j
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling //2.开启定时任务
public class LiveTask {
private final WxLiveService wxLiveService;
public LiveTask(WxLiveService wxLiveService) {
this.wxLiveService = wxLiveService;
}
//定义多长时间执行一次
@Scheduled(cron = "* 1 * * * * ")//3.添加定时任务
void Live(){
log.info("正在执行定时任务");
wxLiveService.updateLive();
}
}