package com.example.demo.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
@Configuration //1.主要用于标记配置类,兼备Component的效果
@EnableScheduling //2.开启定时任务
public class QuartzController {
private static final Logger logger = LoggerFactory.getLogger(QuartzController.class);
//3.添加定时任务
@Scheduled(cron = "#{@getCronValue}")
//或直接指定时间间隔,例如:5秒
//@Scheduled(cron = "fixedRate=5000")
public void noticeNews(){
//执行定时任务,调用service
}
@Bean
public String getCronValue(){
String cron = "";
return cron;
}
}
schedule执行定时任务quartz
最新推荐文章于 2023-12-04 21:40:02 发布