我正在使用这样的春季时间表。
@Component
@EnableScheduling
public class ScheduledTasks {
@Autowired
private ISomeJob someJob;
/**
* do a Job every 5 minutes.
*/
@Scheduled(cron = "0 0/5 * * * ?")
public void foo(){
someJob.doSomething();
}
}
有效。但是有一个问题
我有两个名为debug
和release
的个人资料
我希望debug
每隔5分钟完成一次这项工作,但release
每小时一次
那么有没有办法在application.properties中配置cron
的值。
答案 0 :(得分:5)
只需添加表达式@Scheduled(cron = "${some.profile.cron}")
即可根据所选的个人资料交换cron
。