天天看點

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

繼續閱讀