JAXB - Property “Value” is already defined. Use

2020-01-27 10:11发布

Using JAXB to generate XML binding classes.

The schema is based on a set of legacy XML files, and includes this snippet:

<xs:complexType name="MetaType">
    <xs:simpleContent>
        <xs:extension base="xs:string">
            <xs:attribute type="xs:string" name="Name" />
            <xs:attribute type="xs:string" name="Scheme" />
            <xs:attribute type="xs:string" name="Value" />
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>

The 'Value' attribute conflicts with the 'value' property of xs:string, and the code generation fails with the error:

com.sun.istack.SAXParseException2: Property "Value" is already defined. Use &lt;jaxb:property> to resolve this conflict. 

标签: java xsd jaxb
7条回答
欢心
2楼-- · 2020-01-27 10:52

I had a problem using the solution with Eclipse (tried both Helios SR1 and Juno SR1) and CXF 2.6.3. The solution was similar to what Kaitsu says. Namely the New > Web Service wizard of Eclipse copies the wsdl into the foldre WebContent/wsdl. I had to place the wsdl and the binding file there myself. Otherwise the binding file gave the "is not a part of this compilation" error.

I wasn't able to use an inline schema in the WSDL but it did work with an external schema like in answer #1.

I'm using the CXF Servlet endpoint config option. In my WSDL I have:

<wsdl:port binding="axis2:ConverterSOAP12Binding" name="ConverterSOAP12port_http">
  <soap12:address location="http://localhost/Converter/services/Converter"/>
</wsdl:port>

The wizard generated this into my web.xml, which works ok:

<servlet-mapping>
  <servlet-name>cxf</servlet-name>
  <url-pattern>/services/*</url-pattern>
</servlet-mapping>

But it put this into cxf-servlet.xml:

<jaxws:endpoint xmlns:tns="http://wtp" id="converterporttype"
implementor="wtp.ConverterPortTypeImpl" wsdlLocation="wsdl/Converter.wsdl"
endpointName="tns:ConverterSOAP12port_http" serviceName="tns:Converter"
address="/ConverterSOAP12port_http">
  <jaxws:features>
    <bean class="org.apache.cxf.feature.LoggingFeature" />
  </jaxws:features>
</jaxws:endpoint>

I had to change the address into the full URL, like this:

address="http://localhost:8080/Converter/services/Converter">
查看更多
登录 后发表回答