微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决验证包含Java 11中从外部http源导入的xsd模式

在example.xsd文件中,我导入了一个看起来像这样的外部xsd文件

select t.start_time + interval tally.n hour,count(*)
from t join
     (select @rn := @rn + 1 as n
      from t cross join
           (select @rn := -1) params  -- so it starts from 0
      limit 100
     ) tally
     on t.start_time + interval tally.n hour <= t.end_time
group by t.start_time + interval tally.n hour;

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

<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>

启动服务器时,出现以下异常:

schema_reference:未能读取架构文档'swaref.xsd',因为由于accessExternalSchema属性设置的限制,不允许'http'访问。

为了解决该问题,我尝试了不同的操作,例如:

  • 设置@Bean public XsdSchema schema() { return new SimpleXsdSchema(new ClassPathResource("example.xsd")); } @Bean public XmlValidator schemaValidator(XsdSchema xsdSchema) { return xsdSchema.createValidator()); // throws exception }
  • 设置System.setProperty("javax.xml.accessExternalSchema","all");
  • 在jdk / lib和jdk / jre / lib下创建jaxp.properties文件,并在其中添加System.setProperty("javax.xml.accessExternalDTD","all");
  • 将xsd中的导入更改为javax.xml.accessExternalSchema = all会导致不同的异常-无法将名称'wsi:swaRef'解析为一个(n)'类型定义'组件。

Java 11,Gradle 5.5.1,Spring Boot 2.1.6,jaxws-ri 2.3.2

如何使其正常工作?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。