之前,我有一个主要的应用程序-context.xml中定义有两个位置的属性占位符:默认的属性文件和可选的覆盖文件:设置系统属性或环境变量属性的占位符与基于SpringJUnit4ClassRunner
<context:property-placeholder
location="classpath:config.properties,${configOverride}"
ignore-resource-not-found="true" />
可选覆盖位置允许仅指定应被覆盖的属性指定另一个属性文件(例如“-DconfigOverride = file:/home/app/config.properties”)。
对于我的单元测试,我使用的进口APP-context.xml的测试背景:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:test-context.xml"})
public class UserServiceTest {
...
}
我如何可以设置应用程序上下文之前在应用程序内的系统属性或环境变量加载?我希望获得与在所有测试类中设置“-DconfigOverride = classpath:testConfig.properties”相同的效果,而不必指定命令行参数(如果可能)。的
感谢您的建议+1 - 我想过的是同样的事情,但在我去修改所有测试类之前,我想要检查在应用程序上下文中是否有任何事情可以做。我在测试上下文中重写了几个bean,但不幸的是,由于允许多个属性占位符,我无法重写该属性占位符。 – andy