Search code examples
kotlinmicronaut

Micronaut access application.yml with @Value


Hello i have a micronaut application with this application.yml

micronaut:
    application:
        name: hello-world
pref:
    msg: Luca

inside a class i want to set the value of a variable :

@Value("${pref.msg}")
private lateinit var text : String

but the IDE complains saying that annotation argument must be a compile time constants

i also tried with

@Property(name = "pref.msg" )

but it compiles but do not read the property.

Anyone could help?


Solution

  • You need to escape $ char using a backslash, because dollar is used by kotlin for template espressions.

    @Value("\${pref.msg}")