The attribute required is undefined for the annotation type XmlElementRef
异常描述:
几天没用的项目导进Eclipse中发现有异常
public class BooleanFeatureType
extends FeatureBaseType{ @XmlElementRef(name = "Value", namespace = "http://schemas.sean.com/ma/CA/OPM/",
type = JAXBElement.class, required = false)
protected JAXBElement<Boolean> value;
......
@XmlElementRef那行报错:The attribute required is undefined for the annotation type XmlElementRef 异常分析:
刚开始有点摸不到头绪,因为这部分代码是使用JAXB根据schema自动生成的,schema定义如下:
<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:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="FeatureBaseType">
<xsd:sequence>
<xsd:element name="Value" type="xsd:boolean" nillable="true" minOccurs="0">
<xsd:annotation>
<xsd:documentation>The feature value, true or false.</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
尝试重新生成了一下,发现重新生成的代码中没有required属性了
public class BooleanFeatureType
extends FeatureBaseType{ @XmlElementRef(name = "Value", namespace = "http://schemas.sean.com/ma/CA/OPM/",
type = JAXBElement.class)
protected JAXBElement<Boolean> value;
......
项目当前使用JDK1.6.0_45,于是看了下JDK1.6.0_45中XmlElementRef注解的定义
@Retention(RUNTIME)
@Target({FIELD,METHOD})
public @interface XmlElementRef {
Class type() default DEFAULT.class; String namespace() default ""; String name() default "##default"; static final class DEFAULT {}
}
发现定义中根本没有required属性,换成JDK1.7.0_65之后,再看下XmlElementRef注解的定义
@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 be required.
* <p>
* If required() is true, then Javabean property is mapped to
* an 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, then the Javabean property is mapped
* to XML Schema element declaration 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>,
* despite the fact that {@link XmlElement#required()} defaults to false.
*
* @since 2.2
*/
boolean required() default true;
}
看来主要的原因是使用的JDK版本不同,注解的定义也是不同的
通过required属性的注释部分,可以确定required属性是从JAXB 2.2开始添加到XmlElementRef注解定义中的
当然,JAXB 2.2的内容从JDK1.6开始,已经被添加到rt.jar中了 解决方式:
如果需要required属性,可将JDK换为1.7,如果不需要,将JDK换为1.6的,再使用JAXB重新生成代码即可
当然了,如果必须要用JDK1.6,而且需要支持required属性,那么JDK1.6 + jaxb-api(我使用的是jaxb-api-2.2.1.jar,仅仅加入jaxb-api-2.2.1.jar代码便不会报错了,但是如果想使用JAXB生成代码,仅仅只有api是不够的,还需要其它相关jar,比如:jaxb-impl-2.2.1.jar)也是可以满足要求的
The attribute required is undefined for the annotation type XmlElementRef的更多相关文章
- 项目重新部署后报The attribute required is undefined for the annotation type XmlElementRef
在另外一台机器上部署项目,项目导进Eclipse中发现有异常 public class BooleanFeatureType extends FeatureBaseType{ @XmlElementR ...
- Annotation Type @bean,@Import,@configuration使用--官方文档
@Target(value={METHOD,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented public @interface Bean ...
- Attribute name "aphmodel" associated with an element type "mxg" must be followed by the ' = ' charac
1.错误描述 org.apache.batik.transcoder.TranscoderException: null Enclosed Exception: Attribute name &quo ...
- Attribute "resultType" must be declared for element type "insert"或"update"
Attribute "resultType" must be declared for element type "insert"或"update&q ...
- Annotation Type EnableTransactionManagement
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/transaction/annotation/Ena ...
- Multiple annotations found at this line: - The content of element type "mapper" must match "EMPTY". - Attribute "namespace" must be declared for element type "mapper".
今天在mybatis的mapper映射配置文件中遇到了这样的问题,困扰了我3个小时: Multiple annotations found at this line: - The content of ...
- The operator == is undefined for the argument type(s) int, null
package cn.edu.shu.web.test; public class TestInteger { public static void main(String[] args) { /** ...
- Attribute "not-null" must be declared for element type "property"解决办法
Attribute "not-null" must be declared for element type "property"解决办法 在hiberante ...
- junit的Test不能使用,报错信息:Test is not an annotation type
在使用junit的Test做测试时,注解@Test报错”Test is not an annotation type”,发现是因为测试类的类名命名为了Test,所以导致错误. 测试类类名不能直接命名为 ...
随机推荐
- Chapter 3 Phenomenon——19
His unfriendliness intimidated me. 他的不友好恐吓到了我. My words came out with less severity than I'd intende ...
- Linux-(ping,traceroute,ss)
ping命令 1.命令格式: ping [参数] [主机名或IP地址] 2.命令功能: ping命令用于:确定网络和各外部主机的状态:跟踪和隔离硬件和软件问题:测试.评估和管理网络.如果主机正在运行并 ...
- linux sticky
文件的粘滞位(sticky)位是作什么用的? 普通文件的sticky位会被linux内核忽略, 目录的sticky位表示这个目录里的文件只能被owner和root删除 粘着位(Sticky bit) ...
- MFC RichText 滚动条问题
一共涉及两个问题: 1.如何更加轻快的在RichText不覆盖之前的文本而添加新的文本 CString text("add text\n"); //想插入的文本,为了使下次输入我们 ...
- java权限控制以及变量的初始化
知识是靠积累的,不断的温习会帮你让你遇到许多问题,解决完这些问题之后,会收获许多,233333333333333. 1.java访问控制符 2.java变量初始化问题 默认构造方法的名字与类名相同,它 ...
- AngularJS学习笔记(五)自定义指令(1)
先来说说自定义指令 ng通过内置指令的方式实现了对html的增强,同时也赋予了我们自定义指令的功能,让我们根据实际需求进行指令的定制.自定义指令涉及到模板(template).作用域(scope).数 ...
- Visual Studio 命令提示符
Visual Studio 命令提示和 SDK 命令提示会自动设置环境变量,使您能够轻松使用 .NET Framework 工具. 在 .NET Framework 4 版 和更高版本中,应使用 Vi ...
- windows下使用python操作redis(Visual Studio Code)
1.编辑工具: Visual Studio Code(windows环境) 2.redis服务器:这里用了远程连接,需要配置redis.conf. (1)注释 #bind 127.0.0.1 (2)设 ...
- 【C#设计模式-抽象工厂模式】
一.抽象工厂模式的定义: 为创建一组相关或相互依赖的对象提供一个接口,而且无需指定他们的具体类. 二.抽象工厂模式的结构: 抽象工厂模式是所有形态的工厂模式中最为抽象和最具一般性的一种形态.抽象工厂模 ...
- c# XML 有多个重复子节点操作
1,继续添加ebm子节点 public static void CreateXml() { //创XML建对象 XmlDocument doc = new XmlDocument(); //声明根节点 ...