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

前端 未结 10 527
野趣味
野趣味 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:38

    Try this:

    @RunWith(SpringJUnit4ClassRunner.class)
    @SpringApplicationConfiguration(classes = TestApplication.class, 
        initializers = ConfigFileApplicationContextInitializer.class)
    public class SomeTestClass {
        ...
    }
    

    EDIT:

    For Spring Boot version 1.5+, SpringApplicationConfiguration was removed in favour of SpringBootTest or direct use of SpringBootContextLoader.

    You can still use initializers parameter with ContextConfiguration annotation.

提交回复
热议问题