我正在使用带有kotlin的spring 5,我有以下代码
@Scheduled(cron = "${job.notification.expiring.x}")
fun notify() {
}
并在application.yml
中job:
notification:
expiring.x: 0 0 12 1/1 * ?
在@schedulled
的行上,cron
参数注释Intellij说
An annotation parameter must be a compile-time constant.
如何解决这个问题,在Java中,属性是在运行时加载的。
答案 0 :(得分:5)
你需要转义Kotlin中的$字符,因为它用于字符串模板:
@Scheduled(cron = "\${job.notification.expiring.x}")
请参阅本页底部的字符串模板部分: