I have the following:
app.properties
indexes=1,2;2,3;3,4
I'd like to bind these properties to List<Index>
, but can't figure out the proper SpEL syntax.
Index.java
public class Index {
public Index(int x, int y) {
this.x = x;
this.y = y;
}
}
Right now I'm splitting the values within constructor by semicolon delimiter then building a list.
Service.java
...
List<Index> indexList;
public Service(@Value(value = "#{'${indexes}'.split(';')}")
List<String> properties) {
List<Index> result = new ArrayList<>();
for (String s : properties) {
String[] split = s.split(",");
Index index = new Index(Integer.valueOf(split[0]), Integer.valueOf(split[1]));
result.add(index);
}
this.indexList = result;
}
Can I do that with a single line? Like:
@Value(value = "some_spring_magic")
List<Index> indexList;