Spring Boot如何编写一个定时任务呢?
下文笔者讲述Springboot编写定时任务的方法及示例分享,如下所示
借助@Scheduled 即可配置一个定时任务例:SpringBoot开启一个定时任务的示例
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* @author java265.com
*/
@Component
@EnableScheduling // 开启定时任务
public class ScheduleTask {
/**
* corn表达式
* 每天0点执行
*/
@Scheduled(cron = "0 0 0 */1 * ?")
private void configureTasks() {
System.err.println("定时任务执行");
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


