Similar to this question: http://forum.springsource.org/showthread.php?111992-Loading-a-list-from-properties-file-using-Value-annotation (for which there's no reply on)
I want to have a list of values in a .properties file, ie:
my.list.of.strings=ABC,CDE,EFG
And to load it in my class directly, ie:
@Value("${my.list.of.strings}")
private List<String> myList;
As I understand, an alternative of doing this is to have it in the spring config file, and load it as a bean reference (correct me if I'm wrong), ie
<bean name="list">
<list>
<value>ABC</value>
<value>CDE</value>
<value>EFG</value>
</list>
</bean>
But is there any way of doing this? using a .properties file? ps: I would like to do this with out any custom code if possible.
All the above answers are correct. But you can achieve this in just one line. Please try following declaration and you will get all the comma separated values in a String list.
And also you need to have the following line defined in your xml configuration.
just replace the path and file name of your properties file. And you are good to go. :)
Hope this helps you. Cheers.