You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Java结合Smooks实现JSON转EDIFACT时schema缺失报错如何解决

问题根因

你遇到的报错是因为自定义的EDIFACT映射DFDL Schema隐式依赖Smooks官方的EDIFACT基础解析Schema EDIFACT-Interchange.dfdl.xsd,该文件没有被放到项目资源加载路径下,导致Smooks初始化时找不到关联依赖。

解决方法

  • 补全基础Schema依赖
    从Smooks EDIFACT扩展组件包中提取EDIFACT-Interchange.dfdl.xsd及其关联的基础Schema(如EDIFACT-Segments.dfdl.xsd、EDIFACT-CompositeElements.dfdl.xsd等),将这些文件放到和你自定义的edi-to-xml-mapping.dfdl.xsd、edi-to-xml-order-mapping.dfdl.xsd同层级的资源目录下。
  • 修正自定义Schema的导入路径
    打开你自己编写的两个DFDL映射Schema文件,找到头部import EDIFACT-Interchange.dfdl.xsd的配置行,将schemaLocation属性的值改为和实际文件存放位置匹配的相对路径,不要使用/开头的绝对路径,避免类路径加载时定位失败。
  • 调整smooks配置的Schema引用写法
    将smooks-config.xml中两个schemaURI属性的路径改为类路径相对路径,参考配置如下:
    <smooks-resource-list
      xmlns="https://www.smooks.org/xsd/smooks-2.0.xsd"
      xmlns:edifact="https://www.smooks.org/xsd/smooks/edifact-2.0.xsd">
    
    <edifact:unparser   unparseOnElement="/Order" schemaURI="classpath:edi-to-xml-mapping.dfdl.xsd" segmentTerminator="%NL;" compositeDataElementSeparator="^"/>
    
    <edifact:parser schemaURI="classpath:edi-to-xml-order-mapping.dfdl.xsd" segmentTerminator="%NL;" dataElementSeparator="*"
                  compositeDataElementSeparator="^"/>
    </smooks-resource-list>
    
  • 本地验证排查
    测试阶段可以临时将Schema路径写成本地绝对路径(如file:///your/local/path/EDIFACT-Interchange.dfdl.xsd),确认所有Schema本身无格式错误、版本和你使用的Smooks EDIFACT扩展版本匹配后,再改回类路径相对路径部署。

内容的提问来源于stack exchange,提问作者Mohamed Mseddi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 21:27:03