我正在尝试从application.yml文件加载字符串数组。这是配置:
ignore:
filenames:
- .DS_Store
- .hg
这是课程:
@Value("${ignore.filenames}")
private List<String> igonoredFileNames = new ArrayList<>();
同一类中还有其他配置也可以加载。我的yaml文件中没有标签。我仍然得到以下异常:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'ignore.filenames' in string value "${ignore.filenames}"
我的 猜测 是,@Value
不能应对“复杂”类型。您可以使用以下prop类:
@Component
@ConfigurationProperties('ignore')
class IgnoreSettings {
List<String> filenames
}
请注意: 此代码是 Groovy的 - 不是Java -保持示例短!有关如何采用的提示,请参见注释。
参见完整示例https://github.com/christoph-frick/so-springboot-yaml-string-
list