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

Ayl*_*ake 1 java spring annotations config

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

有没有办法配置:

在测试环境中:预定选择fixedDelay = 10000

在产品环境中:预定选择 cron = "0 10 0 5 * ?"

这个注解语法糖filed=value在java中叫什么?

Dea*_*ool 5

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

应用程序.yml

 scheduler: 
    fixedDelay: 1000
Run Code Online (Sandbox Code Playgroud)

在java类中

  @Scheduled(fixedDelayString = "${scheduler.fixedDelay}")
  public void task() {
  }
Run Code Online (Sandbox Code Playgroud)

注意:3.2.2它只接受长值之前,但3.2.2它也将接受字符串