【问题标题】:JAXB custom binding - Prefix must resolve to a namespaceJAXB 自定义绑定 - 前缀必须解析为命名空间
【发布时间】:2021-08-30 01:42:00
【问题描述】:

我正在尝试使用 maven-jaxb2-plugin 从 WSDL 生成 java 类,但没有成功。 WSDL 包含一个名为 stringArray 的复杂类型的两个定义,因此我试图创建一个自定义绑定,以便两个类在创建时不会发生冲突。问题是我不断收到此错误:

XPath: javax.xml.transform.TransformerException: Prefix must resolve to a namespace: wsdl

我的 Maven maven-jaxb2-plugin 插件配置是这样的:

<plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.14.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
                    <generatePackage>com.arkdia.seus.service.stamping.xml.invoice.cancel.implementation.finkok</generatePackage>
                    <schemas>
                        <schema>
                            <url>https://demo-facturacion.finkok.com/servicios/soap/cancel.wsdl</url>
                        </schema>
                    </schemas>
                    <bindingDirectory>${project.basedir}/src/main/resources/finkok/bindings</bindingDirectory>
                    <bindingIncludes>
                        <include>bind.xjb</include>
                    </bindingIncludes>
                </configuration>
            </plugin>

我的 bind.xjb 有以下内容:

<jaxb:bindings version="1.0"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jaxb:extensionBindingPrefixes="xjc">
    <jaxb:bindings
        node="/wsdl:definitions[@targetNamespace='http://facturacion.finkok.com/cancel']/wsdl:types/xs:schema[@targetNamespace='http://facturacion.finkok.com/cancellation']">
        <jaxb:bindings
            node="/xs:complexType[@name='stringArray']">
            <jaxb:factoryMethod name="CancelStringArray" />
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

我使用online tool 测试了 XPath,它看起来是正确的,但是当我使用 Maven 编译 mi 代码时,我得到了我之前提到的错误。

我做错了什么?

编辑:

WSDL 定义是here

感谢@LMC,我注意到命名空间丢失并更新了 mi bind.xjb 以添加它,但现在我收到此错误:

xpath evaluation of results in empty target node

编辑 2:

根据@LMC 的建议,我更新了我的 bind.xjb 文件以包含架构位置。但是现在即使我为冲突的复杂类型定义了一个新的类名,我也会收到这个错误:

two declarations cause a collision in the ObjectFactory class

我的新 bind.xjb 是这样的

<jaxb:bindings version="1.0"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jaxb:extensionBindingPrefixes="xjc">
    <jaxb:bindings
        schemaLocation="https://demo-facturacion.finkok.com/servicios/soap/cancel.wsdl"
        node="/wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='http://facturacion.finkok.com/cancellation']/xs:complexType[@name='stringArray']">
        <jaxb:class name="CancellationStringArray" />
    </jaxb:bindings>
    <jaxb:bindings
        schemaLocation="https://demo-facturacion.finkok.com/servicios/soap/cancel.wsdl"
        node="/wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='http://facturacion.finkok.com/cancel']/xs:complexType[@name='stringArray']">
        <jaxb:class name="CancelStringArray" />
    </jaxb:bindings>
</jaxb:bindings>

【问题讨论】:

  • bind.xjb 中没有定义wsdl 命名空间。请在问题中添加 wsdl 代码。
  • @LMC 我添加了指向 WSDL 的链接
  • 在第二个 binfings 元素中尝试&lt;jaxb:bindings schemaLocation="https://demo-facturacion.finkok.com/servicios/soap/cancel.wsdl" node="/wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://facturacion.finkok.com/cancellation']"&gt;
  • 它解决了这个问题。现在我回到我原来的问题,我该如何解决冲突?

标签: java maven jaxb jaxb2-maven-plugin


【解决方案1】:

最后一个问题是因为有第三个同名元素,所以最终的bind.xjb是这样的

<jaxb:bindings version="1.0"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jaxb:extensionBindingPrefixes="xjc">
    <jaxb:bindings
        schemaLocation="https://demo-facturacion.finkok.com/servicios/soap/cancel.wsdl"
        node="/wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='http://facturacion.finkok.com/cancellation']/xs:complexType[@name='stringArray']">
        <jaxb:class name="CancellationStringArray" />
    </jaxb:bindings>
    <jaxb:bindings
        schemaLocation="https://demo-facturacion.finkok.com/servicios/soap/cancel.wsdl"
        node="/wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='http://facturacion.finkok.com/cancellation']/xs:element[@name='stringArray']">
        <jaxb:class name="CancellationStringArrayElement" />
    </jaxb:bindings>
</jaxb:bindings>

感谢 @LMC 帮助识别 jaxb:bindings 中缺少的命名空间声明和缺少的 schemaLocation

【讨论】:

    猜你喜欢
    • 2020-03-15
    • 2015-02-01
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多