-1

I have a "details.yml" file, considering all the setting for getting all values from "yml.file" is done. But I am unable to store Map values into "Map"

Here is my "details.yml"  file below


details: 
  company:XYZ
  values:
     name: Manish
     last: Raut

And in my class file i am able to get the values of "company" from yml file using @Value("${company}")

@Component
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "details")
public class abcd() {

   @Value("${company}")
   String company;

   @Value("${values}")
   Map<String, String> values =new HashMap<String, String>();
  ...............................

}

i am not able to get those values in Mao which i created in this class, but i am getting values for "Company".

Help me with this?

Manish
  • 61
  • 1
  • 9
  • Hope below link can help you. [https://stackoverflow.com/questions/24917194/spring-boot-inject-map-from-application-yml](https://stackoverflow.com/questions/24917194/spring-boot-inject-map-from-application-yml) – Ankit Thakkar Aug 10 '17 at 07:13

2 Answers2

0

Im the past, I added getter/setter for MAP type and it was work.
Did you try it? (getter/setter for 'values')

Bui Anh Tuan
  • 910
  • 6
  • 12
0

I'm not really sure what marshalling framework Spring uses behind the scenes and how it configures it (you could probably find out with some debugging and maybe make it work for your case), but you could always add an extra layer to your application and configure your own.

For instance you could use Jackson with yaml dataformat - https://dzone.com/articles/read-yaml-in-java-with-jackson.

Catalin
  • 474
  • 4
  • 19