我想在src / test / resources文件夹中仅指定要在同名的测试属性文件中覆盖的属性.
更多细节……
在maven布局中,我有一个属性文件,其中包含要使用的部署值(例如input.uri).
src/main/resources/app.properties:
input.uri=jms:topic:in
app.name=foo_bar
property-placeholder将此文件的属性加载到context.xml文件中:
src/main/resources/Meta-INF/spring/context.xml:
我在src / test / resources文件夹中有一个名为app.properties的测试属性文件,并将input.uri定义覆盖到我的junit测试将使用的定义. (注意,app.name不会改变).
src/test/resources/app.properties:
input.uri=seda:in
您将如何编写junit测试和/或测试context.xml文件,以便从src / main / resources / app.properties文件加载属性,但是在src / test / resources / app.properties文件中定义的任何属性覆盖src / main / resources / app.properties文件中的那些?如果你在src / main文件或src / test junit测试文件中加载两个不同的文件是显而易见的 – 我希望属性占位符搜索类路径并选择正确的值.
最佳答案
您必须提供不同的名称 – 如果main和test中的属性具有相同的名称,则一个或另一个中的整个属性将生效.
相反,像这样的方法对我有用:
在你的src / main / resources / Meta-INF / spring / context.xml中执行以下操作:
在test-context.xml文件中:
Meta-INF/spring/context.xml">