###1.首先需要在配置中开启spring框架自带的任务调度器,开启代码如下
代码语言:javascript复制import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
@Configuration
@EnableScheduling
public class SpringScheduleConfig {
}
###2.在需要使用的地方使用注解@Scheduled来配置任务的具体调度时间等
代码语言:javascript复制package schedule;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class TestTask {
@Scheduled(cron = "0 * 14 * * ? ") // 14点每分执行的任务
public void minuteJob() {
System.out.println("do somthing....");
}
}