Java - Spring Ws - 在 XSD 文件中加载相对包含 (Tomcat 8)

Java - Spring Ws - Loading Relative Includes in XSD files (Tomcat 8)

我创建了一个 Spring Web 服务,它使用以下代码从 XSD 个文件的集合创建一个动态 WSDL:

Resource[] schema = {
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/coreschemas/NarrativeBlock.xsd"),
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/coreschemas/datatypes-base.xsd"),
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/coreschemas/infrastructureRoot.xsd"),
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/multicacheschemas/PRPA_IN201305UV02.xsd"),
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/NE2008/multicacheschemas/PRPA_IN201306UV02.xsd"),
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/IHE/XCPD_PLQ.xsd"),
            new ClassPathResource(
                    "schema/service/XCPD.SupportMaterials.v9/schema/HL7V3/XCPD_PRPA.xsd") };
    CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(
            schema);
    collection.setInline(true);
    return collection;

用于创建动态 WSDL 的 XSD 文件包括使用 include 语句的其他各种模式文件,如下所示:

<xs:include schemaLocation="../coreschemas/voc.xsd"/>
<xs:include schemaLocation="../coreschemas/datatypes.xsd"/>

当我 运行 代码在 Tomcat 8 容器中时,我收到以下异常:

Caused by: java.lang.IllegalArgumentException: The resource path [/../coreschemas/infrastructureRoot.xsd] has been normalized to [null] which is not valid

Spring 的 URI 解析器在路径前面加上“/”,即使被引用的这个文件是相对路径(不是绝对路径)并且在导入架构时失败。

请注意,此应用程序 运行 在 Tomcat 7 上运行良好。当尝试将其迁移到 Tomcat 8 时,出现了问题。

Tomcat 8 确实改变了现在加载 Web 资源的方式。 More Information from Java CodeRanch...

长话短说,有没有办法强制 Spring URI 解析器正确处理相关文件?如果我查看解析器 Spring 上的 "collectionBaseURI" 属性 使用 (ClasspathUriResolver),则此值为空。是否也可以设置此基本 URI?

编辑 我可以通过将所有相对路径转换为架构的绝对路径来解决此问题...但是我不想在数百个文件中应用此修复程序。

万一有人遇到这个烦人的问题,ClasspathUriResolver 就是罪魁祸首,它在相对路径包含的前面加了一个“/”。我将它切换为使用默认的 URI 解析器(在 org.apache.ws.commons.schema.resolver.DefaultURIResolver 中)并且它在 Tomcat 8.

上运行良好没有问题
CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(schema);
collection.setUriResolver(new DefaultURIResolver());
collection.setInline(true);
return collection;