2012-05-22 37 views
1

在.net spring land中,您可以聲明自定義變量源,並在彈簧配置中執行${variableName}樣式變量。您可以通過實現一個接口(IVariableSource)做到這一點,它看起來像這樣:java spring config是否有能力解析來自自定義變量解析器的變量?

<object type="Spring.Objects.Factory.Config.VariablePlaceholderConfigurer, Spring.Core"> 
    <property name="VariableSources"> 
     <list> 
      <ref object="MyVariableSource" /> 
     </list> 
    </property> 
</object> 

<object id="TestObject" type="TestProject.TestObject, TestProject" singleton="false"> 
    <constructor-arg type="string" value="${MyVariableDefinedInMyVariableSource}" /> 
</object> 

這樣做有什麼用Java春耕備耕的相同呢?

回答

0

您也可以在Java中也達到同樣的效果。下面是例子。

<bean id="propertyConfigurer" 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location" value="classpath:config/config.properties" /> 
</bean> 

<bean id="myController" 
    <property name="variableName" value="${variableName}" /> 
</bean> 
+0

謝謝,我看到了PropertyPlaceHolderConfigurer的文檔,但它不完全相同。我沒有讀取屬性文件中的值,而是從數據庫中讀取值 –