@Scheduled 动态配置
时间: 2023-10-13 18:04:40 浏览: 98
springboot动态配置定时任务(schedule)
5星 · 资源好评率100%
@Scheduled注解的动态配置可以通过在配置文件中添加cron表达式来实现。首先,在application.yml或application.properties文件中添加一个cron属性,例如:scheduled.cron.test: "*/10 * * * * ?"。然后,在启动类上添加@EnableScheduling注解,确保定时任务的开关已打开。接下来,在需要进行定时任务的方法上添加@Scheduled注解,并使用cron属性引用配置文件中的cron表达式,例如:@Scheduled(cron = "${scheduled.cron.test}")。这样就可以实现动态配置@Scheduled注解的cron表达式。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Spring定时器@Scheduled 以及getBean](https://blog.csdn.net/qq_45524246/article/details/114263846)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [@Scheduled 动态配置cron](https://blog.csdn.net/weixin_47951400/article/details/123872305)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [spring boot @scheduled定时任务配置](https://download.csdn.net/download/qq_37900963/10373885)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文