在Spring Boot中如何使用定时任务

电子说

1.2w人已加入

描述

本文介绍在 Spring Boot 中如何使用定时任务,使用非常简单,就不做过多说明了。

com.kfit.base.scheduling.SchedulingConfig:

package com.kfit.base.scheduling;

importorg.springframework.context.annotation.Configuration;

import org.springframework.scheduling.annotation.EnableScheduling;

importorg.springframework.scheduling.annotation.Scheduled;

/**

  • 定时任务
  • @author Administrator

*/

@Configuration

@EnableScheduling

public****class SchedulingConfig {

@Scheduled(cron = "0/20 * ** * ?") // 每20秒执行一次

public****void scheduler() {

System. ***out*** .println(">>>>>>>>>SchedulingConfig.scheduler()");

}

}

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分