在Java11中验证包含从外部http源导入的xsd模式

k0pti3hp  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(220)

在example.xsd文件中,我导入了一个外部xsd文件,如下所示:

<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://test.example.com"
        xmlns:wsi="http://ws-i.org/profiles/basic/1.1/xsd">
<import namespace="http://ws-i.org/profiles/basic/1.1/xsd" schemaLocation="http://ws-i.org/profiles/basic/1.1/swaref.xsd" />
<element name="attachment" type="wsi:swaRef" />
</schema>

在配置文件中,我创建了xsdschema和验证器bean

@Bean
public XsdSchema schema() {
  return new SimpleXsdSchema(new ClassPathResource("example.xsd"));
}

@Bean
public XmlValidator schemaValidator(XsdSchema xsdSchema) {
  return xsdSchema.createValidator()); // throws exception
}

启动服务器时出现以下异常:
架构\u引用:未能读取架构文档“swaref.xsd”,因为由于accessexternalschema属性设置的限制,不允许“http”访问。
为了解决这个问题,我尝试了不同的方法,例如:
设置 System.setProperty("javax.xml.accessExternalSchema", "all"); 设置 System.setProperty("javax.xml.accessExternalDTD", "all"); 在jdk/lib和jdk/jre/lib下创建jaxp.properties文件并添加 javax.xml.accessExternalSchema = all 在那里
将xsd中的导入更改为 <import namespace="http://ws-i.org/profiles/basic/1.1/xsd"/> 这将导致不同的异常-无法解析名称的wsi:swaref'到(n)'类型定义'组件。
java 11、gradle 5.5.1、spring boot 2.1.6、jaxws ri 2.3.2
如何让它工作?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题