正在验证包含从Java 11中的外部http源导入的xsd架构
在example.xsd文件中,我导入了一个外部xsd文件,如下所示:正在验证包含从Java 11中的外部http源导入的xsd架构,java,spring,xsd,Java,Spring,Xsd,在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="
<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>
启动服务器时,出现以下异常:
架构_引用:未能读取架构文档“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中的导入更改为
,这会导致不同的异常-无法将名称“wsi:swaRef”解析为(n)“类型定义”组件
@Bean
public XsdSchema schema() {
return new SimpleXsdSchema(new ClassPathResource("example.xsd"));
}
@Bean
public XmlValidator schemaValidator(XsdSchema xsdSchema) {
return xsdSchema.createValidator()); // throws exception
}