0

我正在使用 commons-configuration 1.10,并且希望仅在需要时创建我的配置文件。

目前,我有

        XMLConfiguration config= new XMLConfiguration(file);
        config.setReloadingStrategy(new FileChangedReloadingStrategy());
        config.setAutoSave(true);

但是,当我尝试打电话时

        config.setProperty("portal.0.name", portal.getName());

我明白了

Caused by: org.apache.commons.configuration.ConfigurationException: org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified. 
    at org.apache.commons.configuration.XMLConfiguration.createDocument(XMLConfiguration.java:914)
    at org.apache.commons.configuration.XMLConfiguration.save(XMLConfiguration.java:1034)
    at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration$FileConfigurationDelegate.save(AbstractHierarchicalFileConfiguration.java:570)
    at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:557)
    at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:524)
    at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:474)
    at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:441)
    at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:418)
    at org.apache.commons.configuration.AbstractFileConfiguration.possiblySave(AbstractFileConfiguration.java:749)
    ... 29 more
Caused by: org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified. 
    at org.apache.xerces.dom.CoreDocumentImpl.createElement(Unknown Source)
    at org.apache.commons.configuration.XMLConfiguration$XMLBuilderVisitor.insert(XMLConfiguration.java:1529)
    at org.apache.commons.configuration.HierarchicalConfiguration$BuilderVisitor.visitBeforeChildren(HierarchicalConfiguration.java:1734)
    at org.apache.commons.configuration.HierarchicalConfiguration$Node.visit(HierarchicalConfiguration.java:1401)
    at org.apache.commons.configuration.HierarchicalConfiguration$Node.visit(HierarchicalConfiguration.java:1407)
    at org.apache.commons.configuration.XMLConfiguration$XMLBuilderVisitor.processDocument(XMLConfiguration.java:1504)
    at org.apache.commons.configuration.XMLConfiguration.createDocument(XMLConfiguration.java:908)
    ... 37 more

这似乎表明文件无法通过自动保存机制保存。

那么,是不是我做错了什么?

以及如何在仅在需要时创建文件时创建配置(否则将需要一些奇怪的 XML 文件副本)

4

1 回答 1

0

我使用portal.0.name了我应该使用的地方portal(0).name,这通过……好吧……阅读文档来解决。

于 2015-02-06T13:34:11.537 回答