Spring boot, read yml properties via integration test case

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

    Here's how I got it to work:

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(initializers=ConfigFileApplicationContextInitializer.class)
    public class MyTestClass {
    
      @Autowired
      private ConfigurableApplicationContext c;
    
      @Test
      public void myTestMethod() {            
         String value = c.getEnvironment().getProperty("myapp.property")
         ...
      }
    }
    

提交回复
热议问题