我正在构建两个使用 commons-configuration XMLConfiguration 的应用程序。由于应用程序是相关的,我构建了另一个项目,称为 commons,它有一个自定义配置管理器,可以像这样初始化 XMLConfiguration:
config = new XMLConfiguration("conf/config.xml");
发生的事情是“命令行”应用程序工作正常,正在加载配置文件。但是当我尝试在 Web 应用程序(使用 Tomcat)上使用我的自定义配置管理器时,我得到了一个
org.apache.commons.configuration.ConfigurationException: Cannot locate configuration source
我已经把conf目录放在了WEB-INF文件夹、根文件夹和META-INF文件夹中。我也尝试过 "/conf/config.xml"
、"./conf/config.xml"
和 "../conf/config。 xml”
。
我唯一一次让它工作 - 在网络应用程序上 - 是使用绝对路径。
我错过了什么?
谢谢, 布鲁诺
最佳答案
使用 ServletContext.getResourceAsStream(..)
,并传递流。或者如果文件在类路径中,您可以使用 getClass().getResourceAsStream(..)
关于java - "Cannot locate configuration source"在 Tomcat 中使用 commons-configuration XMLConfiguration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4520252/