Spring .properties file: get element as an Array
If you define your array in properties file like:
base.module.elementToSearch=1,2,3,4,5,6
You can load such array in your Java class like this:
@Value("${base.module.elementToSearch}") private String[] elementToSearch;
And incase you a different delimiter other than comma, you can use that as well.
@Value("#{'${my.config.values}'.split(',')}")private String[] myValues; // could also be a List<String>
and
in your application properties you could have
my.config.values=value1, value2, value3
Here is an example of how you can do it in Spring 4.0+
application.properties
content:
some.key=yes,no,cancel
Java Code:
@Autowireprivate Environment env;...String[] springRocks = env.getProperty("some.key", String[].class);