Java Apache Commons Configuration2中的FileBasedConfiguration Builder未写入配置文件

Java Apache Commons Configuration2中的FileBasedConfiguration Builder未写入配置文件,java,apache,apache-commons-config,Java,Apache,Apache Commons Config,我需要使用apachecommons配置编写一个简单的配置文件,但不管我怎么做,它都不会向该文件写入任何内容 这就是文件的外观 <config> <foo>bar</foo> </config> FileBasedConfiguration不应该为我处理这个问题吗,或者这是一个没有在apachecommons上记录的步骤?我正在尝试找到这个问题的答案,我也在尝试,只是为了一个简单的属性文件。按照文档中的相同步骤操作,但当我检查applicat

我需要使用apachecommons配置编写一个简单的配置文件,但不管我怎么做,它都不会向该文件写入任何内容

这就是文件的外观

<config>
  <foo>bar</foo>
</config>

FileBasedConfiguration
不应该为我处理这个问题吗,或者这是一个没有在
apachecommons
上记录的步骤?

我正在尝试找到这个问题的答案,我也在尝试,只是为了一个简单的属性文件。按照文档中的相同步骤操作,但当我检查application.properties文件时,它没有更新我的更改。@Clawdir,这看起来像是刷新问题,您是否确定要从生成器中调用save方法?@martinatime yeeah,很遗憾我当时找不到这个问题的答案。。。如果有人发现是否有自动创建文件的方法,我很乐意接受答案。谢谢!:)@马格纳西门托,我能解决这个问题。问题是我把我的属性文件放在哪里。它现在位于WEB-INF/classes/application.properties中,正在更新中。我现在的问题是,PropertyPlaceHolderConfigure无法获取更改:/
private static final String USER_CONFIGURATION_FILE_NAME = "config.xml";

private final Path configFilePath = Paths.get(System.getProperty("user.home"), ".myapp",
USER_CONFIGURATION_FILE_NAME);

private final FileBasedConfigurationBuilder<XMLConfiguration> configBuilder=
  new FileBasedConfigurationBuilder<>(XMLConfiguration.class)
      .configure(new Parameters().xml().setFile(configFilePath.toFile()));

/**
 * Sets the foo configuration to the given {@link String}
 * 
 * @param foo The configuration to be set up
 * @throws ConfigurationException If any error occur while setting the property on the
 *         configuration file
 */
public void setfoo(final String bar) throws ConfigurationException {
  checkNotNull(bar);
  final Configuration config = configBuilder.getConfiguration();

  config.setProperty("foo", bar);

  configBuilder.save();
}

/**
 * Retrieves the foo set up on the configuration file
 * 
 * @return The foo set up on the configuration file
 * @throws ConfigurationException If any error occur while setting the property on the
 *         configuration file
 * @throws NoSuchElementException If there is no foo set up
 */
public String getFoo() throws ConfigurationException {
  return configBuilder.getConfiguration().getString("foo");
}
configFilePath.toFile().createNewFile();

final Writer writer = Files.newBufferedWriter(configFilePath);
writer.write("<config></config>");  //sets the root element of the configuration file
writer.flush();