import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
@Configuration
@EnableScheduling
public class SpringScheduleConfig {
}
2.在需要使用的地方使用注解@Scheduled来配置任务的具体调度时间等例如:
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class TestTask {
@Scheduled(cron = "00 30 02 * * ?") // 每天02:30分执行博客自动审核任务
public void deleteUnUse() {
System.out.println("do somthing....");
}
}
版权所有 © 【代码谷】 欢迎非商用转载,转载请按下面格式注明出处,商业转载请联系授权,违者必究。(提示:点击下方内容复制出处)
源文:《Spring框架开启自带的任务调度器执行任务(注解方式)》,链接:https://www.daimagu.com/article/75.html,来源:【代码谷】
评论