2

I am trying to get map from my properties file, which goes as below:

Mapping = { "NAME-1":"AAA,aa,bb" , "NAME-2":"BBB,bb,cc" }

In My class file, I am doing this

@Value("${Mapping}")
private String mapping;

@Bean
public Map<String,String> getMapping() {
    log.debug("inside mapping");
    Map<String,String> mapping = new HashMap<String,String>();
    return mapping;
}

Which is not working, please help.

4
  • Pardon me but your question is not clear. Do you have a file named config.properties? Are you trying to create a java.util.Map from the contents of that file?
    – Abra
    Feb 5, 2021 at 9:42
  • @Abra...YES Thats correct
    – R_S_C
    Feb 5, 2021 at 9:43
  • Does this help? docs.oracle.com/javase/tutorial/essential/environment/…
    – Abra
    Feb 5, 2021 at 9:45
  • Thanks @Abra...It cleared my perspective
    – R_S_C
    Feb 5, 2021 at 9:50

1 Answer 1

1
    @Value("#{${Mapping}}")
    private Map<String,String> mapping;

    @Bean
    public Map<String,String> getMapping() {
        return mapping;
    }

This works in a minimal project.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.