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

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

    Unit test with Spring Boot 2

    spring boot 2 support 'application.properties' by default, for 'application.yml' just add below:

    @TestPropertySource(properties = { "spring.config.location=classpath:application.yml" })
    

    e.g.

    @RunWith(SpringRunner.class)
    @SpringBootTest
    @TestPropertySource(properties = { "spring.config.location=classpath:application.yml" })
    public class ServiceTest {...}
    

提交回复
热议问题