3

From config server, I want to inject the property in to my service as a Map. I can do this with @ConfigurationProperties annotation; however using the @Value (along with @RefreshScope) it reads from the config server; however throws an exception: Cannot convert value of type [java.lang.String] to required type [java.util.Map]: no matching editors or conversion strategy found


application.yml:(in config server)
user:
  test:
    key1:
      val1,val2
    key2:
      val1,val2

@Service
//@ConfigurationProperties(prefix="user")
@RefreshScope
public class Example {

    @Value("${user}")
    Map<String, List<String>> test;

}
Swetha V
  • 300
  • 5
  • 16
  • You don't need `@RefreshScope` or `@Service` on `@ConfigurationProperties`. `@ConfigurationProperties` by default is in the refresh scope. – spencergibb Apr 27 '16 at 18:49
  • Thanks for responding. and also the problem that I had of the property not loading as a map from config server is fixed by removing the @value annotation and providing the get/set for test variable. `@ConfigurationProperties(prefix="user") public class Example { Map> test; public Map> getTest() { return test; } public void setTest(Map> tet) { this.test = test; } }` – Swetha V Apr 27 '16 at 19:22
  • Please check my comment about how to read YAML file in Spring and include it in JUnit and TestNG test here: http://stackoverflow.com/a/37270778/3634283 – ayurchuk May 17 '16 at 08:34

0 Answers0