0
我想註釋由jaxb生成的pojos,並且爲此我正在使用maven-jaxb2-plugin,我能夠添加註釋但不能默認值未通過maven-jaxb2-plugin添加到類級別的註釋
我有下面的maven-JAXB2-插件的配置在我的pom.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>
有人可以請建議在那裏我誤以爲,在此先感謝