Search code examples
javaspringpropertiesannotationsintrospection

How to read all properties into an array with spring?


I know you can use spring to read a single property, and to read a single property that has a list of values into a list. But what about reading all the properties from a file into a list?

I.E.

EDIT: The property file we are reading is litterally just a list of values, no key, like the updated example below:

Property File

queueName1
quename2
queName3

...etc (the file is like 100 lines long hence why its not a list of values with one property name)

and then be able to do something like

//Imaginary Code
@Value("${GET ALL THE LINES}")
List<String> eachLineOfPropertyFile;

Solution

  • Can you not use the following

    List<String> list = Files.readAllLines(new File("propertiesFile").toPath(), Charset.defaultCharset() );
    

    PS: This is part of Java 7