有了XSD,我可以从中生成Java类(使用cxf-codegen-plugin和org.jvnet.jaxb2_commons.jaxb2-basics-annotate)
wsdl / Service.xsd片段
<xs:element name="ImportujZpravuRequest">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="Oznameni" nillable="false">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="1" maxOccurs="1" processContents="lax"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
生成的Java类
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {"oznameni"})
@XmlRootElement(name = "ImportujZpravuRequest")
public class ImportujZpravuRequest {
@XmlElement(name = "Oznameni", required = true)
protected Oznameni oznameni;
//getters&setters
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {"any"})
public static class Oznameni {
@XmlAnyElement(lax = true)
protected Object any;
//getters&setters
}
问题 如何注释对象的字段(Java类中的XSD / Oznameni.any中的xs:any),例如带有@Deprecated注释。我尝试过
<jaxb:bindings schemaLocation="wsdl/Service.xsd">
<jaxb:bindings node="//xs:any">
<annox:annotate target="field">@java.lang.Deprecated</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
我能够注释e.q. Oznameni对象(具有更改的节点选择器定义),因此插件配置应该确定。而且XSD文件中只有一个,因此XPATH选择器也应该可以。但我收到以下错误消息
[ERROR] C:\makro\proj\CZLih\czlih-java\src\main\resources\bindings.xml [11:44]: compiler was unable to honor this annotate customization. It is attached to a wrong place, or its inconsistent with other bindings.
com.sun.istack.SAXParseException2; systemId: file:/C:/makro/proj/CZLih/czlih-java/src/main/resources/bindings.xml; lineNumber: 11; columnNumber: 44; compiler was unable to honor this annotate customization. It is attached to a wrong place, or its inconsistent with other bindings.
...
任何帮助将不胜感激。