Spring boot, read yml properties via integration test case

后端 未结 5 1071
太阳男子
太阳男子 2020-12-16 21:08

Hi I am using Spring Boot, I want to inject the values of the .yml file in the Bean. I have written the integration test case but looks like via Integration test case it not

5条回答
  •  借酒劲吻你
    2020-12-16 21:37

    Try this one:

    @SpringApplicationConfiguration(classes = TestBean.class, initializers = ConfigFileApplicationContextInitializer.class)
    

    From its JavaDocs:

    * {@link ApplicationContextInitializer} that can be used with the
    * {@link ContextConfiguration#initializers()} to trigger loading of
    * {@literal application.properties}.
    

    It says that it works with application.properties, but I guess it should work with application.yml as well.

提交回复
热议问题