I have a main app-context.xml that defines a property placeholder with two locations: a default property file and an additional override file:
<context:property-placeholder
location="classpath:config.properties,${configOverride}"
ignore-resource-not-found="true" />
An optional override location allows you to specify a different property file (for example, "-DconfigOverride = file: /home/app/config.properties") with only properties that need to be overridden.
For my unit tests, I use a test context that imports app-context.xml:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:test-context.xml"})
public class UserServiceTest {
...
}
? , "-DconfigOverride = classpath: testConfig.properties" arg, .