首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >@TestPropertySource不工作?

@TestPropertySource不工作?
EN

Stack Overflow用户
提问于 2016-11-11 02:35:52
回答 1查看 5.4K关注 0票数 2

我正在尝试测试我的Spring配置。下面是我的config类

代码语言:javascript
运行
复制
@Configuration
@PropertySource("/etc/my.properties")
@ComponentScan("my.package")
public class SpringConfig {

    @Bean
    .....
}

当我试着通过我的测试来测试它时

代码语言:javascript
运行
复制
@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource(locations = "classpath:test.properties")
@ContextConfiguration(classes = {SpringConfigIntTest.class, SpringConfig.class})
public class SpringConfigIntTest {
    .......
}

我一直收到失败消息,说/etc/my.properties找不到。但我认为我已经用test.properties覆盖了它,我一直在谷歌上搜索,没有看到其他人有不同的做法。

我使用了spring-context、spring-beans、spring-core 4.2.2和spring-test 4.2.4。有没有人能帮帮我?深深地感谢它

EN

回答 1

Stack Overflow用户

发布于 2016-11-15 06:23:15

如果资源不存在,则可以将属性源设置为不失败:

代码语言:javascript
运行
复制
@PropertySource(value = "/etc/my.properties", ignoreResourceNotFound = true)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40534724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档