多个 WSDL 绑定的单个文件

Single file for multiple WSDL binding

我目前正在使用 Apache CXF 的 cxf-codegen-plugin 开发 SOAP 网络服务客户端。因为我有多个 WSDL,所以我需要将它绑定到我的 java 项目中的不同包。

我的问题是,是否可以为多个 WSDL 文件定义 1 个绑定文件?

下面是我的插件配置

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf.version}</version>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <defaultOptions>
                    <bindingFiles>
                        <bindingFile>src/main/resources/wsdl/bindings.xjb</bindingFile>
                    </bindingFiles>
                </defaultOptions>
                <sourceRoot>${basedir}/src/main/java</sourceRoot>
                <wsdlRoot>src/main/resources/wsdl</wsdlRoot>
                <includes>
                    <include>*.wsdl</include>
                </includes>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

我正在努力实现这样的目标,但无济于事

<jaxws:bindings
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" 
    xmlns="http://java.sun.com/xml/ns/jaxws">

    <jaxws:bindings wsdlLocation="serviceA.wsdl" >
        <jaxws:package name="org.ws.serviceA"/>
    </jaxws:bindings>

    <jaxws:bindings wsdlLocation="serviceB.wsdl" >
        <jaxws:package name="org.ws.serviceB"/>
    </jaxws:bindings>

</jaxws:bindings>

事实证明,这确实是不可能的,并且在本站中明确说明

https://jax-ws.java.net/nonav/2.1.2/docs/customizations.html

1.1.1 Root Binding Element

The jaxws:bindings declaration appears as the root of all other binding declarations. This top-level jaxws:bindings element must specify the location of the WSDL file as a URI in the value of wsdlLocation attribute.

但是它没有在子元素上指定任何关于 wsdlLocation 的信息。此站点 http://itdoc.hitachi.co.jp/manuals/3020/30203Y2310e/EY230286.HTM#ID00669

Non-root jaxws:bindings > wsdlLocation > The attribute cannot be specified. Even if the attribute is specified, it is ignored.

希望将来可以改进这一点,因为 JAXB 已经可以像这样在一个文件中绑定多个 schemaLocation

<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <jxb:bindings schemaLocation="schema1.xsd" node="//xsd:schema">
        <jxb:schemaBindings>
            <jxb:package name="org.package1" />
        </jxb:schemaBindings>
    </jxb:bindings>


    <jxb:bindings schemaLocation="schema2.xsd" node="//xsd:schema">
        <jxb:schemaBindings>
            <jxb:package name="org.package2" />
        </jxb:schemaBindings>
    </jxb:bindings>
</jxb:bindings>