映射未从YAML文件值初始化

时间:2017-09-21 14:22:59

标签: java spring spring-boot

我有以下YAML文件内容:

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

这是我的报告配置类。我试图将yaml内容读作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;
    }

我有以下测试类:

@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\\"));

   }

}

reportConfiguration.getReportPaths()返回null的错误是什么?

0 个答案:

没有答案