@TestPropertySource not working?

雨燕双飞 提交于 2019-12-11 03:38:14

问题


I am trying to test my Spring Configuration. Here is my config class

@Configuration
@PropertySource("/etc/my.properties")
@ComponentScan("my.package")
public class SpringConfig {

    @Bean
    .....
}

And when I tried to test it thru my test as

@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource(locations = "classpath:test.properties")
@ContextConfiguration(classes = {SpringConfigIntTest.class, SpringConfig.class})
public class SpringConfigIntTest {
    .......
}

I keep getting the failure saying /etc/my.properties cannot be found. But I think I have overridden it with test.properties and I have been googling around without seeing other people doing it differently.

I am using spring-context, spring-beans, spring-core 4.2.2, and spring-test 4.2.4. Can someone please give me some help here? Deeply appreciate it


回答1:


You can set the property source to not fail if the resource does not exist:

@PropertySource(value = "/etc/my.properties", ignoreResourceNotFound = true)


来源:https://stackoverflow.com/questions/40534724/testpropertysource-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!