[英]If property used for Scheduled annotation is empty, then use a default
I am writing a Spring Batch job and in the Component
class I have: 我正在编写一个Spring Batch作业,在
Component
类中我有:
@Scheduled(cron = "${expression.from.property}")
public void runJob() {
//code
}
This will grab a property from the properties file we have. 这将从我们拥有的属性文件中获取属性。 However, say this property file is missing from the property file, is there a way this can get a default
cron
expression on top of this? 但是,如果属性文件中缺少此属性文件,是否有一种方法可以在此基础上获取默认的
cron
表达式?
You should be able to use the Elvis operator to have a default value 您应该能够使用Elvis运算符来获得默认值
@Scheduled(cron = "${expression.from.property ?:1 0 0 0 0 0}") // or whatever cron expression
public void runJob() {
//code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.