简体   繁体   中英

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:

@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?

You should be able to use the Elvis operator to have a default value

@Scheduled(cron = "${expression.from.property ?:1 0 0 0 0 0}") // or whatever cron expression
public void runJob() {
        //code
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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