Spring Boot properties in 'application.yml' not loading from JUnit Test

前端 未结 10 509
野趣味
野趣味 2021-01-31 13:59

What am I doing wrong? I\'m using this little standalone App which runs and finds my src/main/resources/config/application.yml. The same configuration doesn\'t work

10条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-31 14:33

    Spring boot 2 example:

    private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
            .withInitializer(new ConfigFileApplicationContextInitializer());
    
    @Test public void test() throws Exception {
    
        this.contextRunner
        .withUserConfiguration(TestApplication.class)
        .run((context) -> {
    
            .....
    
        });
    }
    

提交回复
热议问题