如何累积房产占位符?

时间:2014-09-10 08:24:42

标签: java spring applicationcontext

我们有一个经典的Maven,Spring(3.1.1)应用程序,我们在其中创建了一个applicationContext.xml。

在这个文件中,我们声明了一个属性占位符,其中包含外部文件和类路径中的文件。 这里有另一个问题的例子:

<context:property-placeholder location="file:${ADMIN_HOME}/db.properties,classpath:configuration.properties"
ignore-unresolvable="false" ignore-resource-not-found="false" />

它正在发挥作用。

但是现在,我们有一个特定的配置文件用于JUnit测试。 在这个配置文件中,我们导入了第一个,并为经典声明的测试添加了一个属性占位符。

<import resource="applicationContext.xml" />

<context:property-placeholder location="classpath:configuration-test.properties"
    ignore-unresolvable="false" ignore-resource-not-found="false" />

我们在JUnit test中从configuration-test.properties中注入了一个值。

@Value("${junit.user.login}")
private String login;

但是当我们启动JUnit时,会出现错误。 关键&#34; junit.user.login&#34;没有解决。

我们不知道为什么。 有什么想法吗?

谢谢。

1 个答案:

答案 0 :(得分:2)

您的junit是否启动了正确的弹簧环境? 您是否将正确的xml路径添加到测试用例中?

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/my-test-context.xml" })
public class TestCase{}
相关问题