我想用spring設置一個屬性值。使用ref-bean設置spring bean屬性值
<bean id="velocityPropsBean" class="com.test.CustomProperties" abstract="false" singleton="true" lazy-init="false" autowire="default" dependency-check="default">
<property name="properties">
<props>
<prop key="resource.loader">file</prop>
<prop key="file.resource.loader.cache">true</prop>
<prop key="file.resource.loader.class">org.apache.velocity.runtime.resource.loader.FileResourceLoader</prop>
<prop key="file.resource.loader.path">NEED TO INSERT VALUE AT STARTUP</prop>
</props>
</property>
</bean>
<bean id="velocityResourcePath" class="java.lang.String" factory-bean="velocityHelper" factory-method="getLoaderPath"/>
現在我需要做的是將getLoaderPath的結果插入到file.resource.loader.path中。 getLoaderPath的值發生變化,所以必須在服務器啓動時加載。
任何想法如何將velocityResourcePath值插入屬性?
感謝您的回答。我試過了,並得到以下錯誤。我正在使用spring 2.0 - org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:來自類路徑資源[velocity-context.xml]的XML文檔中的第17行無效;嵌套異常是org.xml.sax.SAXParseException:元素類型「prop」的內容必須匹配「null」。 原因:org.xml.sax.SAXParseException:元素類型「prop」的內容必須匹配「null」。 – Pushkar 2011-01-13 00:50:03