0

使用 WSO2 AS 5.2.1 一直无法读取类路径中的 xml 文件。这是代码和伴随的错误:

try {
        InputStreamReader inputReader =new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(xmlFile.getName())); 
        HolidayInitializer holidayInit = new HolidayInitializer();
        XMLInputFactory factory = XMLInputFactory.newInstance();
        XMLStreamReader xmlStreamReader = factory.createXMLStreamReader(inputReader);
        institutionVumcHolidays = holidayInit.processHolidays(xmlStreamReader);
        log.info(getClass().getSimpleName() + " loadHolidays() Found Holidays config file in classpath");
    } catch (Exception e) {
        log.error(getClass().getSimpleName() + " loadHolidays() Holidays config file does not exist in classpath", e);
    }

输出是:

2015-05-26 02:49:14 ERROR ExternalCallbackWebServiceImpl:343 - ExternalCallbackWebServiceImpl loadHolidays() Holidays config file does not exist in classpath

java.io.FileNotFoundException: c:\wso2as-5.2.1\Holidays.xml (No such file or directory)
    at java.io.FileInputStream.open(Native Method)

无论我将 xml 文件放在 WEB-INF/classes 中的什么位置或源文件的目录中,它都会一直在 WSO2_HOME(安装目录)中查找该文件。非常严峻的情况。感谢您的帮助。

4

1 回答 1

0

您可以使用以下内容读取配置文件,

context.getServletContext().getResource("/META-INF/holidays.xml")

谢谢。

于 2015-07-16T09:45:35.317 回答