我有一個XMLConfiguration中bean來加載SystemProperty.xml文件,如下使用的MethodInvokingFactoryBean爲XMLConfiguration中裝載文件中的Spring bean
<bean
id="xmlConfiguration"
class="org.apache.commons.configuration.XMLConfiguration"
lazy-init="true">
<constructor-arg type="java.lang.String">
<value>SystemProperty.xml</value>
</constructor-arg>
<property name="expressionEngine">
<bean class="org.apache.commons.configuration.tree.xpath.XPathExpressionEngine" />
</property>
</bean>
它工作正常,但是,我必須delimiterParsingDisabled在XMLConfiguration中設置爲true,所以我換豆添加一個propery delimiterParsingDisabled
<bean
id="xmlConfiguration"
class="org.apache.commons.configuration.XMLConfiguration"
lazy-init="true">
<constructor-arg type="java.lang.String">
<value>SystemProperty.xml</value>
</constructor-arg>
<property name="expressionEngine">
<bean class="org.apache.commons.configuration.tree.xpath.XPathExpressionEngine" />
</property>
<property name="delimiterParsingDisabled">
<value type="java.lang.Boolean">true</value>
</property>
</bean>
但是,這將無法正常工作。由於setDelimiterParsingDisabled()
必須在文件加載之前調用。因此,我已要求setDelimiterParsingDisabled()
我已經使用了MethodInvokingFactoryBean
這種方式後打電話到XMLConfiguration中的load(String fileName)
,但得到任何異常,如下
org.apache.commons.configuration.ConfigurationException: No file name has been set!
at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:409)
at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:214)
at devicemanage.system.SystemConfigurationServiceImpl.saveSystemProperty(SystemConfigurationServiceImpl.java:232)
at datacollection.service.DataCollectionServiceImpl.syncWithDataCollection(DataCollectionServiceImpl.java:786)
at devicemanage.utility.SyncWithDCListener$1.run(SyncWithDCListener.java:51)
看來,該文件不被設置成XMLConfiguration中,我MethodInvokingFactoryBean
已經說明如下
<bean id="xmlConfigurationMethodInvokingBean"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="xmlConfiguration" />
<property name="targetMethod" value="load" />
<property name="arguments" value="SystemProperty.xml" />
</bean>
和原因,改變我的xmlConfiguration
豆不加載文件,而新的構造如下
<bean
id="xmlConfiguration"
class="org.apache.commons.configuration.XMLConfiguration"
lazy-init="true">
<property name="expressionEngine">
<bean class="org.apache.commons.configuration.tree.xpath.XPathExpressionEngine" />
</property>
<property name="delimiterParsingDisabled">
<value type="java.lang.Boolean">true</value>
</property>
</bean>
不知道的是,我有錯的方式來使用MethodInvokingFactoryBean
或我已經使用的參數傳遞一個文件名字符串錯誤到load()
任何幫助表示讚賞。
嗨,肯,謝謝你的回答!它運作良好。 – Bruce
@布魯斯歡迎您。 –