繁体   English   中英

java如何在属性中配置注释调度程序fixedDelay

[英]java how to config annotation scheduler fixedDelay in properties

@Scheduled(cron = "0 10 0 5 * ?")   
//@Scheduled(fixedDelay = 10000)
public void task() {
}

有没有一种配置方法:

在测试环境中:按计划选择fixedDelay = 10000

在产品环境中:按计划选择cron = "0 10 0 5 * ?"

在Java中调用此注释语法糖filed=value是什么?

从Spring 3.2.2您可以将其添加到配置文件中,并通过Spring表达式语言(application.properties or application.yml)读取。

application.yml

 scheduler: 
    fixedDelay: 1000

在java类中

  @Scheduled(fixedDelayString = "${scheduler.fixedDelay}")
  public void task() {
  }

注意:3.2.2之前,它将仅接受long值,但从3.2.2它将也接受string

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM