简体   繁体   中英

How to cumulate property placeholder?

We have a classic Maven, Spring (3.1.1) application where we created an applicationContext.xml.

In this file, we have declared a property placeholder with an external file and a file in classpath. Here an example found in another question here :

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

It is working.

But now, we have a specific config file for JUnit tests. In this config file, we have imported the first one and added a property placeholder for tests with a classic declaration.

<import resource="applicationContext.xml" />

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

We have injected a value from configuration-test.properties in JUnit test.

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

But when we launch the JUnit, an error is raised. The key "junit.user.login" is not resolved.

We don't know why. Any idea ?

Thank you.

Is your junit launching the correct spring context? You added the correct xml paths to the test case like so?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM