繁体   English   中英

弹簧与kotlin预定注释从属性文件获取参数

[英]spring with kotlin scheduled annotation getting params from properties file

我使用带有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中,属性是在运行时加载的。

您需要转义Kotlin中的$字符,因为它用于字符串模板:

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

请参阅本页底部的字符串模板部分:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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