Small question regarding the spring annotation @Value please.
This annotation is powerful, well known and offers the possibility out of the box to bind types such as boolean, String, and even more complex data structures such as List, Map<String, Integer> via configuration.
@Value("${my.string}")
private String myString;
@Value("${my.flag}")
private Boolean someFlag;
@Value("#{'${my.list.of.strings}'.split(',')}")
private List<String> myListOfStrings;
@Value("#{${my.hashmap}}")
private Map<String, Integer> myHashMap;
application.properties
my.string=something
my.flag=true
my.list.of.strings=hello,world
my.hashmap={'hello':'world','aaa':'bbb','ccc':'ddd'}
Question: Is it possible to use @Value on some POJO I defined please? something like:
@Value("${my.pojo}")
private MyPojo myPojo;
public class MyPojo {
private String firstName;
private String lastName;
private int age;
private boolean isMarried;
}
application.properties
my.pojo={ "firstname": "john", "lastname": "doe", "isMarried": false, "age": 20 }
And have the @Value (or maybe something else) pick it up. I tried above and did not get the myPojo. What would be a solution to have this configurable under @Value please?
Thank you