Spring框架开启自带的任务调度器执行任务(注解方式)

Spring框架开启自带的任务调度器执行任务(注解方式)

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框架开启自带的任务调度器执行任务(注解方式)

相关文章:

你感兴趣的文章:

标签云: