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

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

    Alternative in February 2017:

    @SpringBootTest
    @ContextConfiguration(classes = { TestApplication.class })
    @RunWith(SpringRunner.class)
    public class SomeTestClass {
       ...
    }
    

    the lean variant (withouth @SpringBootTest):

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

提交回复
热议问题