我写了一个测试类来读取定义的属性
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:config/TestOne.xml","classpath*:config/TestTwo.xml"
})
public class PropertyTest {
@Value("${test.one:DEFAULT}")
private String test;
@Value("${test.two:DEFAULT}")
private String test2;
@Test
public void TestProperty(){
System.out.println(test + "," + test2);
}
}
TestOne.xml
<context:property-placeholder
location="classpath*:/config/testone.properties"
ignore-unresolvable="true" order="1" />
测试二.xml
<context:property-placeholder
location="classpath*:/config/testtwo.properties"
ignore-unresolvable="true" order="2" />
testone.properties
test.one=testone
testtwo.properties
test.one=testone
test.two=test
运行测试时,输出为
睾酮,默认
它不是从属性中获取 test.two 。
如果我没有指定默认值
@Value("${test.two}")
private String test2;
输出是 testone,test
有人可以帮忙吗?