如何在application.properties中配置@Scheduled的cron值

时间:2017-06-13 06:19:01

标签: spring cron schedule

我正在使用这样的春季时间表。

@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();
    }
}

有效。但是有一个问题 我有两个名为debugrelease的个人资料 我希望debug每隔5分钟完成一次这项工作,但release每小时一次 那么有没有办法在application.properties中配置cron的值。

1 个答案:

答案 0 :(得分:5)

只需添加表达式@Scheduled(cron = "${some.profile.cron}")即可根据所选的个人资料交换cron