簡體   English   中英

如何對從WSDL生成的類使用JAXB自動繼承?

[英]How to use JAXB autoInheritance for generated classes from WSDL?

我正在從soap webservices wsdl生成Java類。

這些請求不共享一個公共接口,但是我希望它們實現一個接口或擴展一個公共類。

因此,我正在嘗試使用xcj-plugin 該聲明

<extraarg>-xjc-XautoInheritance-xmlRootElementsImplement=com.path.to.BaseInterface</extraarg>

應該注意這一點,並讓所有@XmlRootElement注釋類自動實現定義的BaseInterface

但是生成的類沒有這個。 沒有任何類正在實現此接口。 為什么? 以下配置可能出什么問題?

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <wsdlOptions>
                                <extraargs>
                                    <extraarg>-xjc-XautoInheritance-xmlRootElementsExtend=com.path.to.BaseClass</extraarg>
                                <extraarg>-xjc-XautoInheritance-xmlRootElementsImplement=com.path.to.BaseInterface</extraarg>
                                <extraarg>-fe</extraarg>
                                <extraarg>cxf</extraarg>
                                <extraarg>-mark-generated</extraarg>
                                </extraargs>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.sun.xml.bind</groupId>
                    <artifactId>jaxb-xjc</artifactId>
                    <version>2.2.10-b140310.1920</version>
                </dependency>
                    <dependency>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                            <version>0.8.2</version>
                     </dependency>
                <dependency>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics-runtime</artifactId>
                    <version>0.8.2</version>
                </dependency>
                <dependency>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics-jaxb-xjc</artifactId>
                    <version>2.2.4-1</version>
                </dependency>
                <dependency>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb-xjc</artifactId>
                    <version>2.1.10.1</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

請添加-xjc-XautoInheritance以激活插件。

有關JAXB2 Basics插件的CXF使用,請參見以下頁面

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <wsdlOptions>
            <wsdlOption>
                <wsdl>${basedir}/src/main/wsdl/CustomerService.wsdl</wsdl>
                <bindingFiles>
                    <bindingFile>${basedir}/src/main/wsdl/binding.xml</bindingFile>
                    <bindingFile>${basedir}/src/main/wsdl/binding.xjb</bindingFile>
                </bindingFiles>
                <extraargs>
                    <extraarg>-xjc-XhashCode</extraarg>
                    <extraarg>-xjc-Xequals</extraarg>
                </extraargs>
            </wsdlOption>
        </wsdlOptions>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-basics</artifactId>
            <version><!-- version --></version>
        </dependency>
    </dependencies>
</plugin>

免責聲明:我是JAXB2 Basics插件的作者。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM