异常描述:
几天没用的项目导进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. webkit技术内幕读书笔记 (一)

    本文部分摘录自互联网. Chromeium与Chrome Chromium是Google为发展自家的浏览器Google Chrome而打开的项目,所以Chromium相当于Google Chrome的 ...

  2. 32-hadoop-hbase调优

    1, 数据膨胀后, 才对region进行分区, 效率比较低, 所以需要预创建region, 进行负载均衡写入 package com.wenbronk.hbase; import org.apache ...

  3. MVC源码分析 - Error过滤器

    接 上一篇 内容, 这里先看一下错误处理过滤器. 在看此部分之前, 先看看MVC已经提供的功能吧. 一. MVC 自带功能 1. 配置方法 <system.web> <!--mode ...

  4. linux开机自启动设置,自定义开机启动模版,nginx开机自启动服务

    /etc/init.d 目录,我们把shell脚本放在这个目录下来作为启动脚本 都是用来放服务脚本的,当Linux启动时,会寻找这些目录中的服务脚本,并根据脚本的run level确定不同的启动级别. ...

  5. php还原16进制特殊字符

    特殊字符的16进制表:https://websitebuilders.com/tools/html-codes/ascii/ 可以通过 hexdec() 和 chr()方法来进行转换, 例子: < ...

  6. Windows下编译打包Spice PC客户端

    目录 1 环境搭建 2 编译客户端 3 打包客户端   1 环境搭建 1.1 准备工作 安装启动: 安装替换图标工具: Resource Hacker 安装exe制作工具: NSIS(提取码:3dfp ...

  7. PTA (Advanced Level) 1004 Counting Leaves

    Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to count tho ...

  8. python3 get post请求Yunba RESTful API

    一:主要内容 获取云巴appkey和seckey 状态回复说明 get请求 post请求 二:获取云巴appkey和seckey 1. 注册云巴 在云巴官网,注册一个云巴账号,官网地址:https:/ ...

  9. gitlab之gitlab-ci和gitlab-runner<二>

    1.使用 该版未接入k8s,下一篇会写接入k8s. 配置项目使用gitlab-ci和gitlab-runner,在项目的根目录中添加.gitlab-ci.yml文件,用于触发pipeline. .ho ...

  10. FFmpeg简易播放器的实现-音频播放

    本文为作者原创,转载请注明出处:https://www.cnblogs.com/leisure_chn/p/10068490.html 基于FFmpeg和SDL实现的简易视频播放器,主要分为读取视频文 ...