How to create a Map<String, List> property in properties file that can be injectable using Spring’s @Value



How do I create a Map<String, List<String>> property in properties file that can be injectable using Spring’s @Value?

Example code snippet in Properties java file

@PropertySource({"file:salesforce-service.properties"})
public class Properties {
    @Value("#{${student.hobbies}}")
    private Map<String, List<String>> hobbies;
}

Answer

Here is the answer and the example code snippet in properties file:

student.hobbies={indoor: 'reading, drawing', outdoor: 'fishing, hiking, bushcraft'}

Reference: https://stackabuse.com/the-value-annotation-in-spring/ section –> Injecting into Maps



Source: stackoverflow