【问题标题】:JAXB: Can't work around collision in ObjectFactory class errorJAXB:无法解决 ObjectFactory 类错误中的冲突
【发布时间】:2015-04-27 15:34:53
【问题描述】:

我有几个想要为其生成 Java 存根的 SOAP 服务(在 .Net 中实现)。第一个服务没有问题,但是第二个服务抛出了错误

WSDLToJava Error: 
http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8 [0,0]: Two declarations cause a collision in the ObjectFactory class.
http://localhost/AMS52/ServiceManagement.svc?xsd=xsd11 [0,0]: (Related to above error) This is the other declaration.

对这些东西不太熟悉,我最终发现 wsdl 中的两个导入正在互相踩踏

<wsdl:types>
    <xsd:schema targetNamespace="http://tempuri.org/Imports">
        ...
        <xsd:import schemaLocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8" namespace="http://schemas.datacontract.org/2004/07/Company.Platform.Datatypes.Enums"/>
        ...
        <xsd:import schemaLocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd11" namespace="http://schemas.datacontract.org/2004/07/Company.Platform.Datatypes.ServiceManagement"/>
        ...

第一次导入的 xsd 格式为

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:tns="http://schemas.datacontract.org/2004/07/Company.Platform.Datatypes.Enums" 
           elementFormDefault="qualified"
           targetNamespace="http://schemas.datacontract.org/2004/07/Company.Platform.Datatypes.Enums">
    <xs:simpleType name="DeviceIdiom">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Auto"/>
            <xs:enumeration value="Phone"/>
            <xs:enumeration value="Tablet"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:element name="DeviceIdiom" nillable="true" type="tns:DeviceIdiom"/>
    <xs:simpleType name="ServiceManagementSORType">
    ...

阅读更多,我发现我必须做这样的事情

How to resolve collision in the ObjectFactory on wsdl2java?

所以我的方法是尝试在每个简单类型的末尾添加一个后缀(它们都是简单类型)。

所以我当前的命令行是

./wsdl2java.bat -impl -server -verbose -autoNameResolution -b bindings.xml ServiceManagement.wsdl

我的绑定文件是

<jaxb:bindings    
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    jaxb:version="2.1"> 

    <jaxb:bindings schemalocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8" node="/xs:schema">
         <jaxb:bindings node="//xs:simpleType">
            <jaxb:nameXmlTransform>
                <jaxb:typeName suffix="Enums" />
            </jaxb:nameXmlTransform>
        </jaxb:bindings>
    </jaxb:bindings>        
</jaxb:bindings>

但现在我被这个错误困住了

XPath evaluation of "//xs:schema" results in empty target node

我不知道如何克服这个错误。我开始认为这与它是一个 .Net 服务的事实有关,我必须像这样引用 xsd

http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8

非常感谢任何帮助。

【问题讨论】:

    标签: java xsd jaxb


    【解决方案1】:

    终于想通了,我换了

    <jaxb:bindings schemalocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8" node="/xs:schema">
    

    <jaxb:bindings schemaLocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8" node="/xs:schema">
    

    不是很容易看到,但请注意 schemaLocation 中的大写 L - 哎哟!

    最终通过将“Company.Platform.Datatypes.Enums”的架构映射到具有绑定文件的不同包来解决整个问题

    <jaxb:bindings    
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    jaxb:version="2.1"> 
    
    <jaxb:bindings schemaLocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8">
        <jaxb:schemaBindings>
          <jaxb:package name="org.tempuri.enums"/>
        </jaxb:schemaBindings>      
    </jaxb:bindings>        
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-16
      • 1970-01-01
      • 2015-02-06
      • 2016-10-20
      • 2018-08-21
      • 2021-12-21
      • 2019-09-15
      • 1970-01-01
      相关资源
      最近更新 更多