@TestPropertySource is not loading properties

后端 未结 2 1980
长发绾君心
长发绾君心 2021-01-13 03:23

I\'m writing integration test for my spring boot application but when I try to override some properties using @TestPropertySource, it\'s loading the property file defined in

相关标签:
2条回答
  • 2021-01-13 04:05

    I tested this feature with Spring Boot 1.4 Line below works pretty well

    @TestPropertySource(properties = { "key=value", "eureka.client.enabled=false" })
    

    Nevertheless new @SpringBootTest annotation is working as well

    @RunWith(SpringRunner.class)
    @SpringBootTest(
        webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
        properties = { "key=value", "eureka.client.enabled=false" }
    )
    public class NewBootTest {
    
        @Value("${key}")
        public String key;
    
        @Test
        public void test() {
            System.out.println("great " + key);
        }
    }
    
    0 讨论(0)
  • 2021-01-13 04:08

    I had a similar problem. I fixed it by updating the Spring Context beans.xml to use org.springframework.context.support.PropertySourcesPlaceholderConfigurer instead of org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.

    From the JavaDoc of PropertyPlaceholderConfigurer

    Deprecated. as of 5.2; use org.springframework.context.support.PropertySourcesPlaceholderConfigurer instead which is more flexible through taking advantage of the Environment and PropertySource mechanisms.

    0 讨论(0)
提交回复
热议问题