0
votes

I've got application.yml in my spring boot project and want to declare empty list. I mean there is a two level config hierarchy. This class is required to get values declared in application.yml

@Configuration
@ConfigurationProperties("book")
public class PropertiesReader {

    private List<Long> authors;

    public List<Long> getAuthors() {
        return new ArrayList<>(authors);
    }

    public void setAuthors(List<Long> authors) {
        this.authors= new ArrayList<>(authors);
    }

And this is how part of application.yml looks like

book:
   library: ${LIBRARY_REFERENCE:library}
   secondValue:
      expirationAfter: 10
   authors: ${AUTHORS_IDS:[]}

So values in curly brackets are declared in another, external configuration file. But if value isn't there declared, spring should assign default value that is declared after colon symbol. In single values it works, but in List if I declare it as above I'm getting NumberFormatException because value [] is assigned to list. How to write it properly?

In external configuration how should it be written also? If I want sometimes to declare values but sometimes it must be empty

name: AUTHORS_IDS
      value: 
1

1 Answers

0
votes

You only need to put a colon sign. I have solved my problem like that, it works.

book:
   authors: ${AUTHORS_IDS:}