JAXB使用JAX-WS绑定生成可序列化的类

Boz*_*zho 9 java cxf jax-ws jaxb

拥有JAXB-RI和CXF.WSDL优先.我想要一个生成的类来实现Serializable.我现在有以下绑定xml,它可以工作(SEI类名称被更改)

<jaxws:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...>
    <bindings node="wsdl:definitions/wsdl:portType[@name='Foo']">
        <!-- change the generated SEI class -->
        <class name="IFooService" />
    </bindings>
</jaxws:bindings>
Run Code Online (Sandbox Code Playgroud)

不,在这种情况下,我应该添加的位置和内容.我试过了:

<xsd:annotation>
    <xsd:appinfo>
        <jaxb:globalBindings>
            <xjc:serializable uid="12343" />
        </jaxb:globalBindings>
    </xsd:appinfo>
</xsd:annotation>
Run Code Online (Sandbox Code Playgroud)

<jxb:globalBindings>
    <jxb:serializable/>
</jxb:globalBindings> 
Run Code Online (Sandbox Code Playgroud)

<bindings>标记内部和外部- 要么Serializable未添加,要么根本不生成类(没有任何错误).

见此主题

那么,究竟如何做到这一点

Boz*_*zho 7

我以两种方式工作:

  1. 使用第二个绑定文件,只有JAXB,就像Pascal在他的回答中所显示的那样

  2. 通过指定<bindings>处理整个命名空间的另一个标记:

    <bindings
        node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://www.yoursite.com/services/mynamespace']">
        <jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
            xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <jxb:serializable />
        </jxb:globalBindings>
    </bindings>
    
    Run Code Online (Sandbox Code Playgroud)