Spring boot, read yml properties via integration test case

后端 未结 5 1068
太阳男子
太阳男子 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:44

    If you have 'application-test.yml' in resources folder.

    You can try this:

    import org.springframework.test.context.ActiveProfiles;
    @ActiveProfiles("test")
    

    From it's Java Docs:

     * {@code ActiveProfiles} is a class-level annotation that is used to declare
     * which active bean definition profiles should be used when loading
     * an {@link org.springframework.context.ApplicationContext ApplicationContext}
     * for test classes.
     *
     * 

    As of Spring Framework 4.0, this annotation may be used as a * meta-annotation to create custom composed annotations.

提交回复
热议问题