The attribute required is undefined for the annotation type Xmlelementref

Source: Internet
Author: User

Exception Description: Days of useless projects in Eclipse found an exception public class Booleanfeaturetype extends featurebasetype{@XmlElementRef (name = "Value", n Amespace = "http://schemas.sean.com/ma/CA/OPM/", type = Jaxbelement.class, required = false) protected jaxbelement<b Oolean> value, ... @XmlElementRef that line error: The attribute required is undefined for the annotation type Xmlelementref exception analysis: At first it was a little confusing because this part of the code was automatically generated using JAXB based on the schema, which is defined as follows: <xsd:element name= "Booleanfeature" type= "Booleanfeaturetype "minoccurs=" 0 "maxoccurs=" unbounded "><xsd:annotation><xsd:documentation>boolean feature.</xsd: Documentation></xsd:annotation></xsd:element><xsd:complextype name= "BooleanFeatureType" > <xsd:annotation> <xsd:documentation>type for Features with a Boolean (True or False) Value.</xsd:doc umentation> </xsd:annotation> <xsd:complexcontent><xsd:extension base= "Featurebasetype" >< xsd:sequence> <xsd:element name= "Value"Type= "Xsd:boolean" nillable= "true" minoccurs= "0" > <xsd:annotation> <xsd:d               Ocumentation>the feature value, True or false.</xsd:documentation> </xsd:annotation> </xsd:element> </xsd:sequence> &LT;/XSD:EXTENSION&GT;&LT;/XSD:COMPLEXCONTENT&GT;&L T;/xsd:complextype> tried to regenerate it and found that there was no required property in the regenerated code, the public class Booleanfeaturetype extends featurebasetype{@Xm Lelementref (name = "Value", Namespace = "http://schemas.sean.com/ma/CA/OPM/", type = jaxbelement.class) protected Jaxbe Lement<boolean> value, ..... The project currently uses jdk1.6.0_45, so I see the definition of xmlelementref annotation in the next jdk1.6.0_45 @retention (RUNTIME) @Target ({Field,method}) public @    Interface Xmlelementref {Class type () default Default.class;    String namespace () default "";    String name () default "# #default"; The static final class DEFAULT {}} found no required attribute at all in the definition, and after replacing it with jdk1.7.0_65, look at the definition of xmlelementref annotation @retention (RUNTIME) @Target ({Field,method})    Public @interface Xmlelementref {Class type () default Default.class;    String namespace () default "";    String name () default "# #default";     Static final class DEFAULT {}/** * Customize the element declaration to is required. * <p> * If required () is true and then Javabean property was mapped to * a XML schema element declaration with     minoccurs= "1".     * MaxOccurs is ' 1 ' for a single valued property and ' unbounded ' * for a multivalued property. * * <p> * If required () is false and then the Javabean property was mapped * to XML Schema element Declarati     On with minoccurs= "0".     * MaxOccurs is ' 1 ' for a single valued property and ' unbounded ' * for a multivalued property. * * <p> * for compatibility with JAXB 2.1, this property defaults to <tt>true</tt>, * despit     E The fact that {@link xmlelement#required ()} defaults to False. * * @since 2.2 */Boolean required () default true;} It seems that the main reason is that the version of the JDK is different, the definition of the annotations is also different through the comments section of the required property, you can determine that the required property is added to the xmlelementref annotation definition from JAXB 2.2, of course, JAXB 2.2 of the content starts with JDK1.6 and has been added to the Rt.jar solution: If the required attribute is required, You can change the JDK to 1.7, if not, change the JDK to 1.6, then use JAXB to regenerate the code, of course, if you have to use JDK1.6, and you need to support the required property, then JDK1.6 + JAXB-API ( I'm using Jaxb-api-2.2.1.jar, just adding the Jaxb-api-2.2.1.jar code will not be an error, but if you want to use JAXB to generate code, only the API is not enough, but also need other related jars, such as: Jaxb-impl-2.2.1.jar ) can also meet the requirements

The attribute required is undefined for the annotation type Xmlelementref

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.