我正在尝试用Kotlin初始化Spring项目中YAML文件中的属性列表。
对于普通字符串,它可以正常工作,但是当我试图插入一个包含以下错误的列表时,它会失败:
Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'foo.bars' in value "${foo.bars}"
Kotlin代码有以下构造函数参数
@Value("\${foo.bars}")
val foobars: List<String>
yaml文件具有以下值:
foo:
bars:
- test1
- test2
我需要在列表和普通字符串之间做一些不同的事情吗?
发布于 2019-06-19 13:57:04
对于Kotlin来说,描述的解决方案here可以做一些修改:
@Component
@ConfigurationProperties("foo")
class FooBarsProperties {
lateinit var bars: List<String>
}
只需在需要的地方注入FooBarsProperties即可。不要忘记将@EnableConfigurationProperties添加到一些配置类中。
https://stackoverflow.com/questions/55178102
复制相似问题