1

I am working on a spring boot application in which I am configuring my properties in application.properties. My Question is how do I configure map property in .properties file. For String it works fine but not for map.

@Service(value = "myService")
@PropertySource(value = "classpath:application.properties")
@EnableConfigurationProperties
public class MyService
{
    @Value("${my.map.config}")
    private Map mapProperty;

public Map<String, String> getMapProperty()
    {
        return mapProperty;
    }

    public void setMapProperty(Map<String, String> mapProperty)
    {
        this.mapProperty = mapProperty;
    }
}

application.properties:

my.map.config.key1 = value1
my.map.config.key2 = value2

I also tries changing my application.properties file as below but still doesn't work:

my.map.config = {key1: 'value1', key2: 'value2'}

Error:

Caused by: java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Map': no matching editors or conversion strategy found

Let me know how can I get it working through application.properties file?

nanosoft
  • 2,913
  • 4
  • 41
  • 61

0 Answers0