I am trying to initialise a list of properties from a YAML file in a Spring Boot project with Kotlin.
It works fine for a normal string, but fails when I try to init a List with the following error:
Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'foo.bars' in value "${foo.bars}"
The Kotlin code has the following constructor argument
@Value("\${foo.bars}")
val foobars: List<String>
the yaml file has the following values:
foo:
bars:
- test1
- test2
Do I need to do something different between Lists and normal Strings?
Solution described here can be changed a bit for Kotlin:
@Component
@ConfigurationProperties("foo")
class FooBarsProperties {
lateinit var bars: List<String>
}
Simply inject FooBarsProperties where you need it. Don't forget to add @EnableConfigurationProperties to some of your configuration classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With