如何解决Java-Spring Ws-加载XSD文件中的相对包含Tomcat 8
万一任何人遇到这个令人讨厌的问题,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;
解决方法
我创建了一个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资源的方式。 Java
CodeRanch的更多信息 …
长话短说,有没有办法强迫Spring URI解析器正确对待相对文件?如果我查看Spring使用的解析器(ClasspathUriResolver)的“
collectionBaseURI”属性,则该值为null。有没有办法设置此基本URI?
编辑 我可以通过将所有相对路径转换为架构的绝对路径来解决此问题,但是我不想在数百个文件中应用此修复程序。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。