我有一个 xmlConfiguration bean 来加载 SystemProperty.xml 文件,如下所示
<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>
它工作正常,但是,我必须在 XMLConfiguration 中将 delimiterParsingDisabled 设置为 true,所以我更改 bean 以添加属性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()
必须在加载文件之前调用。因此,我必须在调用load(String fileName)
后调用 XMLConfigurationsetDelimiterParsingDisabled()
我用过MethodInvokingFactoryBean
这种方式,但有任何异常如下
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 更改为在新建构造函数时不加载文件,如下所示
<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()
任何帮助表示赞赏。