2013-10-09 30 views

回答

1

您可以使用spring util: 不要忘記導入方案,使用util:map和util:list來構建任何你想要的結構。這是確定使用REF-ID作爲值:

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" 
     xsi:schemaLocation="http://www.springframework.org/schema/util 
     http://www.springframework.org/schema/util/spring-util-2.5.xsd"> 

<util:map id="map1" map-class="java.util.HashMap"> 
    <entry key="smthgkey" value="smthvalue"/> 
</util:map> 

<util:list id="list1" list-class="java.util.ArrayList"> 
    <value>val1</value> 
</util:list> 

另一種方式是必要的結構創造豆,但我從來沒有使用過這種方式。你可以在這裏找到例子:How to define a List bean in Spring?

+0

但如何讓我的動態屬性名稱和值映射? – JMJ

+0

一旦加載屬性,我知道重新加載它們的唯一方法是[刷新](http://docs.spring.io/spring/docs/3.0.5.RELEASE/api/org/springframework/context/support/ AbstractApplicationContext.html#refresh%28%29)上下文。也許最好是創建自定義方法直接從文件(或數據庫)重新加載你的屬性,沒有多餘的上下文操作。 – arghtype

相關問題