Search code examples
javaspringspring-bootspring-io

How can I expand wildcards in Spring properties?


I am developing spring boot application and I want to inject Collections of resources like this:

@Value("${app.users-location}")
Collection<Resource> csvResources;

inside application.properties I wrote following:

app.users-location=/feed/*.csv

But it doesn't work as expected:

/src/main/resources containing a feed folder with 5 CSVs

For that situation I expect to see Collection of 5 elements of type Resource.

How can I achieve it ?


Solution

  • The person with nick m.antkowicz - https://stackoverflow.com/users/4153426/m-antkowicz

    provided correct answer but then removed it.

    https://stackoverflow.com/a/57373605/2674303

    His solution was to use Array instead of list:

    @Value("${app.users-location}")
    Resource[] resources;
    
    @PostConstruct
    public void init(){
        System.out.println(resources);
    }
    

    I checked it and it really works!!!