简体   繁体   中英

spring with kotlin scheduled annotation getting params from properties file

I am using spring 5 with kotlin and I have the following code

@Scheduled(cron = "${job.notification.expiring.x}")
fun notify() {

}

and in application.yml

job:
  notification:
    expiring.x: 0 0 12 1/1 * ?

On the line with the @schedulled , at cron parameter annotation Intellij says

An annotation parameter must be a compile-time constant.

How can I fix this, in Java the properties were loaded at run time.

You need to escape the $ character in Kotlin since this is used for String templates:

@Scheduled(cron = "\${job.notification.expiring.x}")

See the section on String templates at the bottom of this page:

https://kotlinlang.org/docs/reference/basic-types.html

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