注释未通过 maven-jaxb2-plugin 添加到类级别



我正在尝试注释 jaxb 生成的 pojos,为此我正在使用maven-jaxb2-plugin,我可以添加注释,但不能使用默认值

我在我的pom中有maven-jaxb2插件的以下配置.xml

<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>

有人可以建议我错在哪里,提前感谢

通过更改绑定解决了我的问题.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>

最新更新