如何在 application.properties 中配置 @Scheduled 的 cron 值
How to config cron value of @Scheduled in application.properties
我正在使用这样的 spring-时间表。
@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
的值吗?
只需添加表达式 @Scheduled(cron = "${some.profile.cron}")
即可根据所选配置文件交换 cron
。
我正在使用这样的 spring-时间表。
@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
的值吗?
只需添加表达式 @Scheduled(cron = "${some.profile.cron}")
即可根据所选配置文件交换 cron
。