1

我将 cxf-codegen-plugin wsdl2java 与以下绑定文件一起使用:

<jaxb:bindings version="2.1"
           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:bindings>
    <jaxb:globalBindings generateElementProperty="false">
    </jaxb:globalBindings>
</jaxb:bindings>
</jaxb:bindings>

我的问题是我的 xsd 的以下部分

<xs:complexType name="clientType">
            <xs:sequence>
                <xs:element name="name" type="xs:string" minOccurs="0" />
                <xs:choice>
                    <xs:sequence>
                        <xs:element name="phone1" type="xs:string"
                                    minOccurs="1" />
                        <xs:element name="phon2" type="xs:string"
                                    minOccurs="0" />
                    </xs:sequence>
                    <xs:element name="phone2" type="xs:string"
                                minOccurs="1" />
                </xs:choice>
            </xs:sequence>
        </xs:complexType>

我仍然得到一个列表

protected List<JAXBElement<String>> content;

我的 ClientType 类被注释

@XmlElementRefs({
    @XmlElementRef(name = "name", type = JAXBElement.class, required = false),
    @XmlElementRef(name = "phone1", type = JAXBElement.class, required = false),
    @XmlElementRef(name = "phone2", type = JAXBElement.class, required = false)
})

编辑:代码生成插件

<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<executions>
    <execution>
        <id>generate-sources</id>
        <phase>generate-sources</phase>
        <defaultOptions>
            <bindingFiles>
                <bindingFile>${basedir}/src/main/jaxb/bindings.xml</bindingFile>
            </bindingFiles>
            <noAddressBinding>true</noAddressBinding>
        </defaultOptions>
        <configuration>
            <sourceRoot>${basedir}/src/main/java</sourceRoot>
            <wsdlOptions>
                <wsdlOption>
                    <wsdl>${basedir}/src/main/resources/service.wsdl</wsdl>
                    <extraargs>
                        <extraarg>-server</extraarg>
                    </extraargs>
                </wsdlOption>
            </wsdlOptions>
        </configuration>
        <goals>
            <goal>wsdl2java</goal>
        </goals>
    </execution>
</executions>
</plugin>

有没有办法避免使用 JAXBElement 列表而不是 String 列表?

谢谢

4

0 回答 0