簡體   English   中英

Maven-jaxb2-plugin未將注釋添加到類級別

[英]Annotation not added to class level by maven-jaxb2-plugin

我正在嘗試注釋jaxb生成的pojos,為此,我正在使用maven-jaxb2-plugin ,我可以添加注釋,但不能使用默認值

我在pom.xml中配置了maven-jaxb2-plugin

<plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.8.3</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>

            <configuration>
                <extension>true</extension>
                <args>
                    <arg>-Xannotate</arg>
                </args>
                <generatePackage>com.abc.model</generatePackage>
                <schemas>
                    <schema>
                        <fileset>
                            <directory>src/main/xsd</directory>
                            <includes>
                                <include>pojo.xsd</include>
                            </includes>
                        </fileset>
                    </schema>
                </schemas>
                <bindings>
                    <binding>
                        <fileset>
                            <directory>src/main/xsd</directory>
                            <includes>
                                <include>binding.xjb</include>
                            </includes>
                        </fileset>
                    </binding>
                </bindings>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.6.4</version>
                    </plugin>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics-annotate</artifactId>
                        <version>0.6.4</version>
                    </plugin>
                    <plugin>
                        <groupId>com.abc.xxy</groupId>
                        <artifactId>my-custom-annotation</artifactId>
                        <version>1.1.1</version>
                    </plugin>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-namespace-prefix</artifactId>
                        <version>1.1</version>
                    </plugin>
                </plugins>
            </configuration>
        </plugin>

我的xsd和綁定看起來像下面:

XSD

<xs:element name="batch" type="Batch"/>

<xs:complexType name="Batch">
    <xs:sequence>
        <xs:element name='student' type='StudentType' minOccurs='0'
                    maxOccurs='unbounded'/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="StudentType">
    <xs:sequence>
        <xs:element name="firstname" type="xs:string"/>
        <xs:element name="lastname" type="xs:string"/>
        <xs:element name="nickname" type="xs:string"/>
        <xs:element name="marks" type="xs:positiveInteger"/>
    </xs:sequence>
    <xs:attribute name='rollno' type='xs:positiveInteger'/>
</xs:complexType>

捆綁

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:annox="http://annox.dev.java.net"
        xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
        jaxb:extensionBindingPrefixes="xjc annox"
        version="2.1">

    <jaxb:bindings schemaLocation="pojo.xsd" node="/xs:schema">
        <jaxb:bindings node="xs:complexType[@name='Batch']">
            <annox:annotate target="class">
                <annox:annotate annox:class="com.abc.xyx.MyCustomAnnotation"/>
                <!--<annox:annotate target="class">com.abc.xyx.MyCustomAnnotation</annox:annotate>-->
            </annox:annotate>
        </jaxb:bindings>
        <jaxb:bindings node="xs:complexType[@name='StudentType']/xs:sequence/xs:element[@name='firstname']">
            <annox:annotate target="field">
                <annox:annotate annox:class="com.abc.xyx.MyCustomAnnotation"/>
            </annox:annotate>
        </jaxb:bindings>
        <jaxb:bindings node="xs:complexType[@name='StudentType']/xs:sequence/xs:element[@name='lastname']">
            <!--<annox:annotate target="field">@com.abc.xyx.MyCustomAnnotation(propertyAlias = "cemaforr:timestamp")</annox:annotate>-->
            <annox:annotate target="field">
                <annox:annotate annox:class="com.abc.xyx.MyCustomAnnotation"/>
            </annox:annotate>
        </jaxb:bindings>
    </jaxb:bindings>

</jaxb:bindings>

有人可以請我建議我去哪里嗎,謝謝

通過更改binding.xml解決了我的問題,問題是我沒有將字段值傳遞給注釋。

     <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
   <jaxb:bindings
           xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:annox="http://annox.dev.java.net"
           xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
           jaxb:extensionBindingPrefixes="xjc annox"
           version="2.1">

       <jaxb:bindings schemaLocation="pojo.xsd" node="/xs:schema">
           <jaxb:bindings node="xs:complexType[@name='Batch']">
               <annox:annotate target="class">
                   <annox:annotate annox:class="com.abc.xyx.MyCustomAnnotation"/>
               </annox:annotate>
           </jaxb:bindings>
           <jaxb:bindings node="xs:complexType[@name='StudentType']/xs:sequence/xs:element[@name='firstname']">
               <annox:annotate target="field">
                   <annox:annotate annox:class="com.abc.xyx.MyCustomAnnotation">
                       <annox:annotate annox:field="propertyNane">Property Value 1</annox:annotate>
                   </annox:annotate>
               </annox:annotate>
           </jaxb:bindings>
           <jaxb:bindings node="xs:complexType[@name='StudentType']/xs:sequence/xs:element[@name='lastname']">
           <annox:annotate target="field">
               <annox:annotate annox:class="com.abc.xyx.MyCustomAnnotation">
                   <annox:annotate annox:field="propertyNane">Property Value 2</annox:annotate>
               </annox:annotate>
           </annox:annotate>
           </jaxb:bindings>
       </jaxb:bindings>

   </jaxb:bindings>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM