maven-jaxb插件 - 两个类具有相同的XML类型名称

时间:2013-04-05 07:47:37

标签: maven maven-jaxb2-plugin

以下问题,我有2个WSDL文件,我必须生成Stubs。但是两个WSDL文件都包含相同的XML类型名称(第二个WSDL是第一个WSDL的另一个阶段)。

我使用以下配置生成存根:

    <plugins>
    ..
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.7.1</version>
            <executions>
                <execution>
                    <id>ws-source-gen-phase1</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <removeOldOutput>true</removeOldOutput>
                        <extension>true</extension>
                        <schemaDirectory>src/main/resources/META-INF/schema/xyz/</schemaDirectory>
                        <args>
                            <arg>-wsdl</arg>
                            <schemaFiles>src/main/resources/META-INF/schema/xyz/Service1.wsdl</schemaFiles>
                            <arg>-XautoNameResolution</arg>
                        </args>
                        <generatePackage>com.xyz.ws</generatePackage>
                        <generateDirectory>${project.build.directory}/generated-sources/xjc1</generateDirectory>
                    </configuration>
                </execution>
                <execution>
                    <id>ws-source-gen-phase2</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <removeOldOutput>true</removeOldOutput>
                        <extension>true</extension>
                        <schemaDirectory>src/main/resources/META-INF/schema/xyz/</schemaDirectory>
                        <args>
                            <arg>-wsdl</arg>
                            <schemaFiles>src/main/resources/META-INF/schema/xyz/Service2.wsdl</schemaFiles>
                            <arg>-XautoNameResolution</arg>
                        </args>
                        <generatePackage>com.xyz.ws.phase2</generatePackage>
                        <generateDirectory>${project.build.directory}/generated-sources/xjc2</generateDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

这确实会生成我的存根,但如果我尝试将它们与spring-ws一起使用,我会收到以下错误。

的applicationContext.xml:

<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />

<bean id="xyzMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="contextPath"
        value="com.xyz.ws:com.xyz.ws.phase2" />
</bean>
<bean id="xyzUnmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="contextPath"
        value="com.xyz.ws:com.xyz.phase2" />
</bean>

<bean id="xyzServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
    <constructor-arg ref="messageFactory" />
    <property name="marshaller" ref="xyzMarshaller"></property>
    <property name="unmarshaller" ref="xyzUnmarshaller"></property>
    <property name="defaultUri" value="${ThiemeRightAccessService.URI}" />
</bean>

<bean id="XyzServiceClient"
    class="com.ebcont.gtv.radbase.business.service.impl.XyzServiceClientImpl">
    <constructor-arg ref="xyzServiceTemplate"></constructor-arg>
</bean>

错误:

Two classes have the same XML type name "{http://status.ws.xyz.com/}GetXyzObject1". Use 
@XmlType.name and @XmlType.namespace to assign different names to them.
...

1 个答案:

答案 0 :(得分:0)

显然你不能混合com.xyz.wscom.xyz.ws.phase2 - JAXB不会知道要为{http://status.ws.xyz.com/}GetXyzObject1创建的类。

您可能需要为两个包创建两组marshaller / unmarshaller / template / client。