1

I have the following YAML File contents:

reports:
    reportPaths:
      10: \\\\path\\Reports\\
      10M: \\\\path\\Reports\\

This is my Configuration class for reports. I am trying to read in yaml contents as Map:

@ConfigurationProperties(prefix="reports")
public class ReportConfiguration {

    private Map<String, String> reportPaths;

    public Map<String, String> getReportPaths() {
        return reportPaths;
    }

    public void setReportPaths(Map<String, String> reportPaths) {
        this.reportPaths = reportPaths;
    }

I have the following test class:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
        loader = AnnotationConfigContextLoader.class,
        classes = ReportConfiguration.class)
public class ReportConfigurationLoadTest {

    @Autowired
    private ReportConfiguration reportConfiguration;


    @Test
    public void testLoadingOfReportConfigProperties() {

        assertNotNull(reportConfiguration);

        System.out.println("reportPaths = " + reportConfiguration.getReportPaths());
        assertThat(reportConfiguration.getReportPaths(), allOf(
                hasEntry("10", "\\\\path\\Reports\\"));

   }

}

What am I missing for reportConfiguration.getReportPaths() to return null?

M06H
  • 1,675
  • 3
  • 36
  • 76
  • Possible duplicate of [Reading a map from yaml in Java getting null](https://stackoverflow.com/questions/34697611/reading-a-map-from-yaml-in-java-getting-null) – Kh.Taheri Sep 21 '17 at 14:29

0 Answers0