天天看点

SpringBoot 单纯@Value 读取数组配置

# yaml配置文件

# yaml数组
languages:
  - Java
  - Perl
  - Python

#yaml数组采用行内表示法
fruits: ['mango','apple','banana']

colors: red,black,yellow
           
// java.lang.IllegalArgumentException: Could not resolve placeholder 'languages' in value "${languages}"
    @Value("${languages}")
    private String[] languages;

    // java.lang.IllegalArgumentException: Could not resolve placeholder 'fruits' in value "${fruits}"
    @Value("${fruits}")
    private String[] fruits;

    //["red","black","yellow"]
    @Value("${colors}")
    private String[] colors;
           

附加:

https://blog.csdn.net/weixin_39581716/article/details/111170059

https://www.runoob.com/w3cnote/yaml-intro.html

继续阅读