Added @Value for map examples

This commit is contained in:
Erhan KARAKAYA 2018-12-31 03:48:20 +03:00
parent de80339a2a
commit 3bdd542dbf
2 changed files with 30 additions and 1 deletions

View File

@ -45,6 +45,27 @@ public class ValuesApp {
@Value("#{'${listOfValues}'.split(',')}")
private List<String> valuesList;
@Value("#{${valuesMap}}")
private Map<String, Integer> valuesMap;
@Value("#{${valuesMap}.key1}")
private Integer valuesMapKey1;
@Value("#{${valuesMap}['unknownKey']}")
private Integer unknownMapKey;
@Value("#{${unknownMap : {key1:'1', key2 : '2'}}}")
private Map<String, Integer> unknownMap;
@Value("#{${valuesMap}['unknownKey'] ?: 5}")
private Integer unknownMapKeyWithDefaultValue;
@Value("#{${valuesMap}.?[value>'1']}")
private Map<String, Integer> valuesMapFiltered;
@Value("#{systemProperties}")
private Map<String, String> systemPropertiesMap;
public static void main(String[] args) {
System.setProperty("systemValue", "Some system parameter value");
@ -69,5 +90,12 @@ public class ValuesApp {
System.out.println(spelSomeDefault);
System.out.println(someBeanValue);
System.out.println(valuesList);
System.out.println(valuesMap);
System.out.println(valuesMapKey1);
System.out.println(unknownMapKey);
System.out.println(unknownMap);
System.out.println(unknownMapKeyWithDefaultValue);
System.out.println(valuesMapFiltered);
System.out.println(systemPropertiesMap);
}
}

View File

@ -1,3 +1,4 @@
value.from.file=Value got from the file
priority=Properties file
listOfValues=A,B,C
listOfValues=A,B,C
valuesMap={key1:'1', key2 : '2', key3 : '3'}