當在Spring XML配置文件與下面的代碼片斷默認值:彈簧默認屬性值總是默認第二
<util:properties id="defaultConfiguration">
<prop key="test.value">${first.value:notFilledIn}</prop>
</util:properties>
<context:property-placeholder properties-ref="defaultConfiguration" order="605" ignore-unresolvable="true"/>
具有以下屬性被加載:
first.value=first
second.value=second
的值總是作爲「默認」值返回,而不是第一個鍵。
@Value("${test.value}")
private String theValue;
.....
System.out.println("theValue: " + theValue);
輸出:
theValue: notFilledIn
如果我在XML配置改變道具值:
<prop key="test.value">${first.value}</prop>
值回來預期:
theValue: first
爲什麼是總是被拉的默認值,wh第一個值的「鍵」是否存在?
「與所加載的下列屬性」 你怎麼樣加載它們? 你也使用什麼版本的春天?上下文的含義:屬性佔位符根據版本 – roby
的不同而有所不同如果您完全不使用默認值,會發生什麼情況?它注入適當的一個還是引發異常?也許屬性佔位符在上下文中加載太遲? – freakman
我正在使用Spring 4.0.8。上面的最後一個例子顯示了沒有默認值的情況。單個屬性查找工作得很好(沒有默認值)。 – LetsBeFrank