jaxb2:忽略注释

时间:2021-04-08 11:58:40

标签: xml jaxb maven-jaxb2-plugin jaxb2-annotate-plugin

这是我的 maven-jaxb2-plugin 配置:

<build>
   <plugins>
      <plugin>
         <groupId>org.jvnet.jaxb2.maven2</groupId>
         <artifactId>maven-jaxb2-plugin</artifactId>
         <version>0.14.0</version>
         <executions>
            <execution>
               <goals>
                  <goal>generate</goal>
               </goals>
               <configuration>
                  <schemaLanguage>WSDL</schemaLanguage>
                  <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
                  <generatePackage>cat.gencat.catsalut.hes.visor.api.common.domain.incidencies</generatePackage>
                  <!-- <forceRegenerate>true</forceRegenerate> -->
                  <schemaDirectory>${basedir}/wsdl/incidencies</schemaDirectory>
                  <schemaIncludes>
                     <include>InformarIncidencia_v02_00.xsd</include>
                  </schemaIncludes>
                  <args>
                     <arg>-npa</arg>
                     <arg>-no-header</arg>
                  </args>
                  <bindingDirectory>${project.basedir}/wsdl/incidencies</bindingDirectory>
                  <bindingIncludes>*.xml</bindingIncludes>
                  <verbose>true</verbose>
                  <debug>true</debug>
               </configuration>
            </execution>
         </executions>
      </plugin>
   </plugins>
</build>

我的 bindings.xml 文件是:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:annox="http://annox.dev.java.net" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema" jaxb:extensionBindingPrefixes="annox xjc" version="2.1">
   <!-- xmlrootelement -->
   <jaxb:bindings schemaLocation="InformarIncidencia_v02_00.xsd">
      <jaxb:bindings node="//xs:complexType[@name='informarIncidenciaRequest']">
         <annox:annotate target="class">
            <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="informarIncidencia" namespace="http://salut.gencat.cat/hc3/informarincidencia" />
         </annox:annotate>
      </jaxb:bindings>
   </jaxb:bindings>
</jaxb:bindings>

而我的 xsd 是:

<?xml version="1.0" encoding="UTF-8"?>
<WL5G3N0:definitions xmlns:WL5G3N0="http://schemas.xmlsoap.org/wsdl/" xmlns:WL5G3N1="http://salut.gencat.cat/hc3/informarincidencia" name="InformarIncidencia-v2.1" targetNamespace="http://salut.gencat.cat/hc3/informarincidencia">
   <WL5G3N0:types>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://salut.gencat.cat/hc3/informarincidencia" xmlns:tns="http://salut.gencat.cat/hc3/response" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://salut.gencat.cat/hc3/response" version="1.0">
         <xsd:element name="UpdateResponseDocument" type="tns:updateResponseDocument" />
         <xsd:complexType name="updateResponseDocument">
            <xsd:sequence>
               <xsd:element minOccurs="0" name="codiDocument" type="xs:string" />
               <xsd:element minOccurs="0" name="code" type="xs:string" />
               <xsd:element minOccurs="0" name="resultCode" type="xs:string" />
               <xsd:element maxOccurs="unbounded" minOccurs="0" name="result" nillable="true" type="tns:wsMessage" />
            </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="wsMessage">
            <xsd:sequence>
               <xsd:element minOccurs="0" name="executionCode" type="xs:string" />
               <xsd:element minOccurs="0" name="executionDetails" type="xs:string" />
            </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="updateResponse">
            <xsd:sequence>
               <xsd:element minOccurs="0" name="code" type="xs:string" />
               <xsd:element minOccurs="0" name="resultCode" type="xs:string" />
               <xsd:element maxOccurs="unbounded" minOccurs="0" name="result" nillable="true" type="tns:wsMessage" />
            </xsd:sequence>
         </xsd:complexType>
      </xsd:schema>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://salut.gencat.cat/hc3/response" xmlns:tns="http://salut.gencat.cat/hc3/informarincidencia" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://salut.gencat.cat/hc3/informarincidencia">
         <xsd:import namespace="http://salut.gencat.cat/hc3/response" />
         <xsd:element name="informarIncidencia" type="tns:informarIncidenciaRequest" />
         <xsd:element name="informarIncidenciaClinicaResponse" type="tns:informeResponse" />
         <xsd:complexType name="informarIncidenciaRequest">
            <xsd:sequence>
               <xsd:element name="codiEp" type="xs:string" />
               <xsd:element name="codiUp" type="xs:string" />
               <xsd:element name="codiCentre" type="xs:string" />
               <xsd:element name="cip" type="xs:string" />
               <xsd:element minOccurs="0" name="cpc" type="xs:string" />
               <xsd:element minOccurs="0" name="informesDuplicats">
                  <xsd:complexType>
                     <xsd:sequence>
                        <xsd:element maxOccurs="unbounded" minOccurs="0" name="cpcd" type="xs:string" />
                     </xsd:sequence>
                  </xsd:complexType>
               </xsd:element>
               <xsd:element minOccurs="0" name="email" type="xs:string" />
               <xsd:element minOccurs="0" name="telefon" type="xs:string" />
               <xsd:element name="nomMetge" type="xs:string" />
               <xsd:element name="cognom1Metge" type="xs:string" />
               <xsd:element name="cognom2Metge" type="xs:string" />
               <xsd:element name="dniMetge" type="xs:string" />
               <xsd:element name="codiColegiat" type="xs:string" />
               <xsd:element name="motiu" type="xs:string" />
               <xsd:element minOccurs="0" name="altres" type="xs:string" />
               <xsd:element minOccurs="0" name="observacions" type="xs:string" />
            </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType final="extension restriction" name="informeResponse">
            <xsd:sequence>
               <xsd:element minOccurs="0" ref="ns1:UpdateResponseDocument" />
            </xsd:sequence>
         </xsd:complexType>
         <xsd:element name="informarincidenciaResponse" nillable="true" type="tns:informeResponse" />
      </xsd:schema>
   </WL5G3N0:types>
   <WL5G3N0:message name="informarIncidenciaResponse">
      <WL5G3N0:part element="WL5G3N1:informarincidenciaResponse" name="parameters" />
   </WL5G3N0:message>
   <WL5G3N0:message name="informarIncidencia">
      <WL5G3N0:part element="WL5G3N1:informarIncidencia" name="parameters" />
   </WL5G3N0:message>
   <WL5G3N0:portType name="InformarIncidencia-v2.1">
      <WL5G3N0:operation name="informarIncidencia">
         <WL5G3N0:input message="WL5G3N1:informarIncidencia" name="informarIncidencia" />
         <WL5G3N0:output message="WL5G3N1:informarIncidenciaResponse" name="informarIncidenciaResponse" />
      </WL5G3N0:operation>
   </WL5G3N0:portType>
</WL5G3N0:definitions>

尽管如此,我的类 InformarIncidenciaRequest 没有使用 XmlRootElement 进行注释:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "informarIncidenciaRequest", namespace = "http://salut.gencat.cat/hc3/informarincidencia", propOrder = {
    ...
})
public class InformarIncidenciaRequest {

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题:

...
   <args>
      <arg>-npa</arg>
      <arg>-no-header</arg>
      <arg>-Xannotate</arg>
   </args>
   <plugins>
      <plugin>
         <groupId>org.jvnet.jaxb2_commons</groupId>
         <artifactId>jaxb2-basics-annotate</artifactId>
         <version>1.1.0</version>
      </plugin>
   </plugins>
...
相关问题