Load different application.yml in SpringBoot Test

前端 未结 11 1150
天涯浪人
天涯浪人 2020-11-30 22:09

I\'m using a spring boot app which runs my src/main/resources/config/application.yml.

When I run my test case by :

@RunWith(SpringJUnit4ClassRunner.c         


        
11条回答
  •  执念已碎
    2020-11-30 22:46

    You can set your test properties in src/test/resources/config/application.yml file. Spring Boot test cases will take properties from application.yml file in test directory.

    The config folder is predefined in Spring Boot.

    As per documentation:

    If you do not like application.properties as the configuration file name, you can switch to another file name by specifying a spring.config.name environment property. You can also refer to an explicit location by using the spring.config.location environment property (which is a comma-separated list of directory locations or file paths). The following example shows how to specify a different file name:

    java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
    

    The same works for application.yml

    Documentation:

    https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-application-property-files

    https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files

提交回复
热议问题