@Scheduled 动态配置cron

一、在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