Spring Boot – YAML Configuration for List of Strings

configurationspring-bootyaml

I am trying to load an array of strings from the application.yml file. This is the config:

ignore:
    filenames:
        - .DS_Store
        - .hg

This is the class fragment:

@Value("${ignore.filenames}")
private List<String> igonoredFileNames = new ArrayList<>();

There are other configurations in the same class that loads just fine. There are no tabs in my YAML file. Still, I get the following exception:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'ignore.filenames' in string value "${ignore.filenames}"

Best Answer

use comma separated values in application.yml

ignoreFilenames: .DS_Store, .hg

java code for access

@Value("${ignoreFilenames}")    
String[] ignoreFilenames

It is working ;)

Related Question