[英]Dynamic configuration for @Scheduled in Spring Boot
我正在尝试使用配置文件动态配置Spring Boot调度。
目标是在我的application.yml
包含以下内容:
platform:
plata:
schedule:
cron: '0 0 9 * * *'
platb:
schedule:
initialDelay = 20000
fixedDelay = 10000000
我正在努力的是现在如何将这种配置应用于@Scheduled
注释。 我在想以下内容:
Scheduler.java:
@Scheduled("${platform.plata.schedule}")
public void plata() throws CalculationException {
...
}
@Scheduled("${platform.platb.schedule}")
public void platb() throws CalculationException {
...
}
在配置中使用属性的完整路径。
玉米的表述应该是0 0 9 * * *
注意没有'-chars
@Scheduled(cron="${platform.plata.schedule.cron}")
public void withCron() {
//
}
@Scheduled(initialDelayString = "${platform.platb.schedule.initialDelay}" ,fixedDelayString= "${platform.platb.schedule.fixedDelay}")
public void withFixedDelay() {
//
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.