首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring JUnit .properties文件不工作

问Spring JUnit .properties文件不工作
EN

Stack Overflow用户
提问于 2016-05-07 07:55:58
回答 1查看 525关注 0票数 0

下面是我的测试类中的注释配置。

代码语言:javascript
复制
@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource("classpath:jdbc.properties")
@ContextConfiguration({"classpath:applicationContext.xml","classpath:mvc-dispatcher-servlet.xml"})
@WebAppConfiguration

applictionCotnext.xml包括jpa-context.xml,数据库配置为jpa-context.xml,dataSource由jdbc.properties配置。

当我运行测试方法时,由于jdbc.properties中的所有值都为null,无法打开连接。

然后在同一个测试类中添加一个访问属性的方法。

代码语言:javascript
复制
@Inject
private ApplicationContext context;
@Test
public void accessProperties(){
    MutablePropertySources sources = ((ConfigurableApplicationContext) context)
                .getEnvironment().getPropertySources();
    System.out.println("jdbcUrl=="+sources.iterator().next().getProperty("jdbcUrl"));
}

我获得了jdbc网址的成功。怎么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-07 08:06:49

如果您正在使用Apache,则需要将属性文件放在src/test/resources中。那应该是你的财产。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37086010

复制
相关文章

相似问题

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