Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 432
tzortzik Avatar asked Mar 08 '18 10:03

tzortzik


1 Answers

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

like image 190
Plog Avatar answered Oct 21 '22 09:10

Plog