How to parameterize @Scheduled(fixedDelay) with Spring 3.0 expression language?

前端 未结 5 1418
谎友^
谎友^ 2020-11-28 21:21

When using the Spring 3.0 capability to annotate a scheduled task, I would like to set the fixedDelay as parameter from my configuration file, instead of hard-w

5条回答
  •  被撕碎了的回忆
    2020-11-28 21:57

    You can use the @Scheduled annotation, but together with the cron parameter only:

    @Scheduled(cron = "${yourConfiguration.cronExpression}")
    

    Your 5 seconds interval could be expressed as "*/5 * * * * *". However as I understand you cannot provide less than 1 second precision.

提交回复
热议问题