Inject a json Map using Spring’s @Value

@Value("#{${myMap}}")
private Map<String, List<String>> myMap;

Then in application.properties file write it like this:

myMap={'key1':{'value1', 'value2'}, 'key2':{'value1', 'value2', 'value3'}}

or

use @ConfigurationProperties doc1 doc2

Example

For Map properties, you can bind with property values drawn from multiple sources. However, for the same property in multiple sources, the one with the highest priority is used. The following example exposes a Map from AcmeProperties:

@ConfigurationProperties("acme")
public class AcmeProperties {

private final Map<String, MyPojo> map = new HashMap<>();

public Map<String, MyPojo> getMap() {
    return this.map;
    }

 }

yml

acme:
  map:
   key1:
    name: my name 1
    description: my description 1

Fill HashMap from java property file with Spring @Value
You can use the SPEL json-like syntax to write a simple map or a map of list in property file.

simple.map={'KEY1': 'value1', 'KEY2': 'value3', 'KEY3': 'value5'}

map.of.list={\
  'KEY1': {'value1','value2'}, \
  'KEY2': {'value3','value4'}, \
  'KEY3': {'value5'} \
 }
I used \ for multiline property to enhance readability

Then, in Java, you can access and parse it automatically with @Value like this.

@Value("#{${simple.map}}")
Map<String, String> simpleMap;

@Value("#{${map.of.list}}")
Map<String, List<String>> mapOfList;
Here with ${simple.map}, @Value gets the following String from the property file:

"{'KEY1': 'value1', 'KEY2': 'value3', 'KEY3': 'value5'}"
Then, it is evaluated as if it was inlined

@Value("#{{'KEY1': 'value1', 'KEY2': 'value3', 'KEY3': 'value5'}}")
You can learn more in the official documentation