异常描述:
几天没用的项目导进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的更多相关文章

  1. 项目重新部署后报The attribute required is undefined for the annotation type XmlElementRef

    在另外一台机器上部署项目,项目导进Eclipse中发现有异常 public class BooleanFeatureType extends FeatureBaseType{ @XmlElementR ...

  2. Annotation Type @bean,@Import,@configuration使用--官方文档

    @Target(value={METHOD,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented public @interface Bean ...

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

  4. Attribute "resultType" must be declared for element type "insert"或"update"

    Attribute "resultType" must be declared for element type "insert"或"update&q ...

  5. Annotation Type EnableTransactionManagement

    http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/transaction/annotation/Ena ...

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

  7. 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) { /** ...

  8. Attribute "not-null" must be declared for element type "property"解决办法

    Attribute "not-null" must be declared for element type "property"解决办法 在hiberante ...

  9. junit的Test不能使用,报错信息:Test is not an annotation type

    在使用junit的Test做测试时,注解@Test报错”Test is not an annotation type”,发现是因为测试类的类名命名为了Test,所以导致错误. 测试类类名不能直接命名为 ...

随机推荐

  1. 腾讯云点播视频存储(Web端视频上传)

    官方文档 前言 所谓视频上传,是指开发者或其用户将视频文件上传到点播的视频存储中,以便进行视频处理.分发等. 一.简介 腾讯云点播支持如下几种视频上传方式: 控制台上传:在点播控制台上进行操作,将本地 ...

  2. Vue + Element UI 实现权限管理系统 前端篇(五):国际化实现

    国际化支持 1.安装依赖 执行以下命令,安装 i18n 依赖. yarn add vue-i18n $ yarn add vue-i18n yarn add v1.9.4 warning packag ...

  3. 页面打印pdf格式文件

    '<td><button type="button" class="btn btn-primary" data-loading-text=&q ...

  4. 29-hadoop-使用phtonenix工具&分页&数据导入

    因为rowkey一般有业务逻辑, 所以不可以直接使用rowkey进行分页, startkey, endkey 想要使用SQL语句对Hbase进行查询,需要使用Apache的开源框架Phoenix. 安 ...

  5. ActiveMQ专题2: 持久化

    AMQ的持久化问题 前言 ​ 前面一篇AMQ专题中,我们发现对于Topic这种类型的消息,即使将deliveryMode设置为持久化,只要生产者在消费者之前启动.消息生产者发布的消息还是会丢失.这是符 ...

  6. 分布式理论(五)—— 一致性算法 Paxos

    前言 Paxos 算法如同我们标题大图:世界上只有一种一致性算法,就是 Paxos.出自一位 google 大神之口. 同时,Paxos 也是出名的晦涩难懂,推理过程极其复杂.楼主在尝试理解 Paxo ...

  7. C# WinForm 关于窗体最大化时的是否全屏效果与是否遮盖任务栏

    0.新建窗体 及添加按钮 1.  执行如下按钮事件  private void btnFormMax_Click(object sender, EventArgs e)  {     if (this ...

  8. 手机调试 ---- Node启动服务

    最近刚开始做手机端Web网站, 在这段时间遇到过很多坑.比如各个安卓手机的JS兼容性问题,以及安卓手机与苹果手机的差异化. 最近在做一个需求.进入手机站点主页,会弹出置顶APP下载框,用户点击图片,如 ...

  9. linux下安装oracle及weblogic

    安装weblogic 下载weblogic http://www.oracle.com/technetwork/middleware/weblogic/downloads/wls-for-dev-17 ...

  10. 如何高效的使用-Notepad++

    Notepad++功能比 Windows 中的 Notepad(记事本)强大,除了可以用来制作一般的纯文字说明文件,也十分适合编写计算机程序代码.Notepad++ 不仅有语法高亮度显示,也有语法折叠 ...