Reputation: 999
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.
Upvotes: 0
Views: 119
Reputation: 1379
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{}
Upvotes: 2