异常描述:
几天没用的项目导进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. j2ee高级开发技术课程第三周

    一.分析Filter例子(轻量级javaee企业应用实战p132) // 执行过滤的核心方法 public void doFilter(ServletRequest request, ServletR ...

  2. Python高级特性: 12步轻松搞定Python装饰器

    12步轻松搞定Python装饰器 通过 Python 装饰器实现DRY(不重复代码)原则:  http://python.jobbole.com/84151/   基本上一开始很难搞定python的装 ...

  3. 大数据之presto

    1.概述 Presto是一个分布式SQL查询引擎,用于查询分布在一个或多个不同数据源中的大数据集.presto可以通过使用分布式查询,可以快速高效的完成海量数据的查询.它是完全基于内存的,所以速度非常 ...

  4. .Net Core vs .Net Framework 如何为一个应用程序选择一个运行时(翻译)

    .Net Core是下一件大事吗?我已经使用了一段时间了,我倾向认为它是.事实上,我们推测,在2018年,对这项技术熟练的开发人员将会有巨大的需求.但是它和.Net Framework的区别是什么?你 ...

  5. 并发编程之 LinkedBolckingQueue 源码剖析

    前言 JDK 1.5 之后,Doug Lea 大神为我们写了很多的工具,整个 concurrent 包基本都是他写的.也为我们程序员写好了很多工具,包括我们之前说的线程池,重入锁,线程协作工具,Con ...

  6. echart 数据视图 样式重写

    来源http://blog.csdn.net/u010705091/article/details/75212724 echarts折线图的数据视图样式重写 在echarts.js中,点击折线图的数据 ...

  7. VB.NET的MsgBox

    一.可用按钮(指定消息框显示哪些按钮) MsgBoxStyle.OkOnly = vbOKOnly = 0(确定按钮) MsgBoxStyle.OkCancel = vbOKCancel = 1(确定 ...

  8. t3用户-角色-权限hibernate经典配置

    用户-角色-权限hibernate经典配置. 既然有人问起,我就写下说明吧.在文章中间的配置文件那里.权当回忆一下,也帮助更多人.这是以前学校时写的,没有注释.都是贴的代码笔记.看到的莫要见怪.欢迎学 ...

  9. 选择ORACLE数据库字符集

    如何选择数据库的字符集是一个有争议的话题,字符集本身涉及的范围很广,它与应用程序.客户的本地环境.操作系统.服务器等关系很密切,因此要做出合适的 选择,需要明白这些因素之间的关系.另外对字符集的基本概 ...

  10. Hexo的搭建

    Hexo的安装与初始化 1.确保电脑已经安装Node.js,Git 打开GUI Bash,输入以下代码安装Hexo: npm install -g hexo-cli 2.运行以下命令在目标文件夹初始化 ...