@Scheduled 动态配置cron

2022年9月7日09:14:15

一、在application.yml中添加cron

scheduled:
  cron:
    test:"*/10 * * * * ?"

二、在启动类添加@EnableScheduling

@SpringBootApplication@EnableSchedulingpublicclassAlgApplication{publicstaticvoidmain(String[] args){SpringApplication.run(AlgApplication.class, args);}}

三、测试

@Component@Slf4jpublicclassTimeTask{@Scheduled(cron="${scheduled.cron.test}")publicvoidtask(){
        log.info("开始定时任务");}}

四、结果

@Scheduled 动态配置cron

  • 作者:CJ_simple
  • 原文链接:https://blog.csdn.net/weixin_47951400/article/details/123872305
    更新时间:2022年9月7日09:14:15 ,共 355 字。