首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用JAX构建存根错误:“两个声明导致冲突.”

用JAX构建存根错误:“两个声明导致冲突.”
EN

Stack Overflow用户
提问于 2014-03-03 11:58:53
回答 1查看 3.7K关注 0票数 1

我试图在WSDL文件上使用JAX作为第三方,但是我得到了一个错误(详细信息如下)。有人能帮我找出哪里出了问题,以及如何解决吗?

编辑:我可以让它编译,但我不喜欢修复,尤其是我不喜欢我不理解修复。见下文。

代码语言:javascript
复制
[WARNING] src-resolve.4.2: Error resolving component 'q1:CorrectRequest'. It was detected that 'q1:CorrectRequest' is in namespace 'http://schemas.datacontract.org/2004/07/Satori.Infuse.Single', but components from this namespace are not referenceable from schema document 'file:/Users/itunesuser/git/listiq/iac-extension/src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl#types?schema1'. If this is the incorrect namespace, perhaps the prefix of 'q1:CorrectRequest' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:/Users/itunesuser/git/listiq/iac-extension/src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl#types?schema1'.
  line 98 of file:/Users/itunesuser/git/listiq/iac-extension/src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl#types?schema1

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 356 of file:/Users/itunesuser/git/listiq/iac-extension/src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl

[ERROR] (Related to above error) This is the other declaration.   
  line 98 of file:/Users/itunesuser/git/listiq/iac-extension/src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl

这是第98行的情况

代码语言:javascript
复制
<xsd:schema xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/"
    elementFormDefault="qualified" targetNamespace="infuse.satorisoftware.com/2012/08">
    <xsd:element name="Correct">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element
                    xmlns:q1="http://schemas.datacontract.org/2004/07/Satori.Infuse.Single"
                    minOccurs="0" name="request" nillable="true" type="q1:CorrectRequest" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    (MORE xsd ELEMENTS)

</xsd:schema>

这是第356行的情况

代码语言:javascript
复制
<xsd:schema
    xmlns:tns="http://schemas.datacontract.org/2004/07/Satori.Infuse.Single"
    elementFormDefault="qualified"
    targetNamespace="http://schemas.datacontract.org/2004/07/Satori.Infuse.Single">
    <xsd:complexType name="CorrectRequest">
        <xsd:sequence>
            <xsd:element minOccurs="0" name="Client" nillable="true"
                type="xsd:string" />
            <xsd:element xmlns:q5="infuse.satorisoftware.com/2012/08"
                minOccurs="0" name="Input" nillable="true" type="q5:RecordBlock" />
            <xsd:element minOccurs="0" name="OutputFields"
                nillable="true" type="tns:ArrayOfInfuseField" />
            <xsd:element minOccurs="0" name="ReferenceString"
                nillable="true" type="xsd:string" />
            <xsd:element xmlns:q6="infuse.satorisoftware.com/2012/08"
                minOccurs="0" name="Settings" type="q6:Settings" />
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="CorrectRequest" nillable="true" 
        type="tns:CorrectRequest" />

    (MORE xsd ELEMENTS)

</xsd:schema>

编辑:--如果我更改了元素的名称,它就会编译,但是我希望找到一个更好的修复方法,并理解为什么这个修复会工作。

代码语言:javascript
复制
    <xsd:element name="CorrectRequestElement" nillable="true" 
        type="tns:CorrectRequest" />
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-04 10:49:51

所以:这个警告其实没那么有趣。重要的是错误。

这些错误试图告诉我们:

“嗨!我是JAXB,我不知道如何命名我从WSDL生成的Java类,而不知道名称冲突。Herp!Derp!”

解决方案是使用绑定文件,这基本上是用与JAXB相关的指令注释(或修补) WSDL文件的一种方法。

这里有一个很好的端到端的例子,里面有很多背景信息。

在我的特殊情况下,我需要做两件事:

  1. 创建绑定文件
  2. 更改我的POM,以便在WSDL处理阶段使用绑定文件。

绑定文件:

我在这里的目标是告诉JAXB,我希望它为这个WSDL文件的这个部分使用Java类的不同名称:

代码语言:javascript
复制
<xsd:element name="CorrectRequest" nillable="true" 
        type="tns:CorrectRequest" />

这将起到以下作用:

代码语言:javascript
复制
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" 
    xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <bindings schemaLocation="../resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl#types?schema3" version="1.0">
        <schemaBindings>
            <package name="com.satorisoftware.ws.infuseiac-intladdresscorrection" />
        </schemaBindings>

        <!-- rename the value element -->
        <bindings node="//xsd:element[@name='CorrectRequest']">
                <class name="CorrectRequestElement" />
        </bindings>
    </bindings>
</bindings>

更新POM:

我在相关的构建阶段添加了一个bindingsFiles条目:

代码语言:javascript
复制
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>1.12</version>
    <executions>
        <execution>
            <id>import-iac-wsdl</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <inherited>false</inherited>
            <configuration>
                <packageName>com.satorisoftware.ws.infuseiac.intladdresscorrection</packageName>
                <wsdlLocation>com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl</wsdlLocation>
                <staleFile>${project.build.directory}/jaxws/stale/wsdl.intladdresscorrection.done</staleFile>
                <sourceDestDir>${project.build.directory}/generated/jaxws-infuseiac-intladdresscorrection</sourceDestDir>
                <wsdlDirectory>src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection</wsdlDirectory>
                <bindingFiles>
                    <!-- See http://www.jroller.com/gmazza/entry/enhancing_jaxb_artifacts#BindingFile 
                    for an end-to-end-example of doing bindings files for WSDL files. -->
                    <bindingFile>${basedir}/src/main/bindings/bindings-intladdresscorrection.xjb</bindingFile>
                </bindingFiles>
                <!-- <wsdlUrls> <value>https://infuseiac.satorisoftware.com/wsdl/IntlAddressCorrection.2012.12.wsdl</value> 
                    </wsdlUrls> -->

                <!-- Generate JAX-WS 2.0 compatible stubs -->
                <target>2.0</target>
            </configuration>
        </execution>
    </executions>
</plugin>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22146180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档