I am trying to load a global variable in kotlin directly from the application.yml:
telegram:
token: foo
to achieve this, in my class I’ve tried this:
@Value("${telegram.token}")
val botToken: String
But it is throwing an error saying that I need to initialize the property. (For example, this doesn’t throw an error but it is not my expected behaviour):
@Value("${telegram.token}")
val botToken: String = ""
What I want is to inject the config value (foo) into this constant (botToken).
2
Answers
first of all it seems like you could use
@Property(name = "telegram.token")
and then i would attempt
Either add it as a parameter in the constructor of the bean that contains the property:
Or try the following (this makes
botToken
mutable):