第一种可以把Scheduled写到xml文件中进行配置。
第二种在你的类前面添加
@PropertySource("classpath:root/test.props")
然后修改你的@Scheduled(cron="0/5 * * * * ? ") 为 @Scheduled(cron="${jobs.schedule}")
最后test.props 添加 jobs.schedule = 0/5 * * * * ?
使用spring@Schedule注解定时任务时将时间表达式写入配置文件中的方法
最新推荐文章于 2025-10-09 17:53:10 发布
本文介绍两种配置Spring框架中Scheduled定时任务的方法:一种是通过XML文件配置,另一种是在类中使用@PropertySource注解来读取属性文件,从而实现定时任务的灵活配置。
7495

被折叠的 条评论
为什么被折叠?



