import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "User")
@XmlAccessorType(XmlAccessType.FIELD)
public class User {

private String id;

private String username;

private String password;

private Expense e;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

@XmlAttribute(name = "ID")
public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

}

This is a JAXB configuration issue, the JAXB runtime thinks there are  
two properties to be serialized with the same name, one that is the  
protected and field and one which is the JavaBean property method.

"If JAXB binds a class to XML, then, by default, all public members  
will be bound, i.e., public getter and setter
    pairs, or public fields. Any protected, package-visible or private  
member is bound if it is annotated with a suitable
    annotation such as XmlElement or XmlAttribute."

If you annotate your Artifact class with the annotation:

@XmlAccessorType(XmlAccessType.FIELD)

then you do not need to annotate the fields with @XmlElement and the  
setter/getter methods will be ignored.

意思是jaxb的配置问题,成员变量的修饰符为public的可以不设置

@XmlAccessorType(XmlAccessType.FIELD)
如果不是public的字段需要设置此属性。

jaxb异常 Class has two properties of the same name username的更多相关文章

  1. maven之---资源过滤 在java/main/resourse/*.xml ,*.properties引用maven属性${db.username}

    本文主要来源maven实战14.3 为了应对环境的变化,首先使用Maven属性将这个会发生变化的部分提取出来.在上一节的数据库配置中,连接数据库使用的驱动类,URL,用户名和密码都可能发生变化,因此使 ...

  2. Jaxb解析xml准换为javabean

    先说下这个的背景吧,前些日子,有个以前的小同事说刚接触webservice,想解析下xml,记得我学的时候还是dom4j,sax的解析方式,最近看别人的代码用的jaxb的方式,觉得注解起来很简练,所以 ...

  3. @ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常

    @ControllerAdvice 和 @ExceptionHandler 的区别 ExceptionHandler, 方法注解, 作用于 Controller 级别. ExceptionHandle ...

  4. spring配置文件引入properties文件:<context:property-placeholder>标签使用总结

    一.问题描述: 1.有些参数在某些阶段中是常量,比如: (1)在开发阶段我们连接数据库时的连接url.username.password.driverClass等 (2)分布式应用中client端访问 ...

  5. 深度分析:SpringBoot异常捕获与封装处理,看完你学会了吗?

    SpringBoot异常处理 简介 ​ 日常开发过程中,难免有的程序会因为某些原因抛出异常,而这些异常一般都是利用try ,catch的方式处理异常或者throw,throws的方式抛出异常不管.这种 ...

  6. Liferay SDK 6.2与7.0中build.[$username].properties 文件的配置

    这篇文章是针对刚开始开发Liferay的新手写的,希望能够帮到刚入门的开发者减少一些配置上的麻烦. 前提: 1. 下载了Liferay IDE(Liferay的官方开发工具) 2.下载了Liferay ...

  7. 9.19.3 反射和Properties(重要)

    dbinfo.properties文件中的内容:     driver oracle.jdbc.driver.OracleDriver url=jdbc:oracle:thin:@192.168.1. ...

  8. excel中的数据导出为properties和map的方法

    在做项目的过程中,经常需要处理excel数据,特别是和业务人员配合时,业务人员喜欢使用excel处理一些数据,然后交给我们技术人员进行程序处理.利用POI读取写入excel数据,是经常使用的一个情景. ...

  9. javaweb 读取properties配置文件参数

    场景1:在servlet中读取properties配置文件参数 protected void doGet(HttpServletRequest request, HttpServletResponse ...

随机推荐

  1. HDU 4381 Grid

    背包变形. 将操作分为了两类,可以分开处理. 可以dp处理出L[i]:L[i]=-1代表从左到右 i 长度不能被拼凑出来,L[i]!=-1表示从左到右 i 长度能被拼凑出,并且最小费用为L[i]. 反 ...

  2. php mysql数据库 分页与搜索

    <?php/** * Created by coder meng. * User: coder meng * Date: 2016/8/29 10:27 */header("Conte ...

  3. 1305: Substring

    #include <iostream>#include<string.h>#include<stdio.h> using namespace std; #defin ...

  4. shell脚本学习(一)

    1.hbg@HWM:/$ su root密码:root@HWM:/# $表示普通用户, #表示管理员用户root.root是linux系统中权限最高的用户. 2.在bash中,每个变量的值都是字符串. ...

  5. 面向方面编程(AOP)

    简介 如果你很熟悉面向方面编程(AOP),你就会知道给代码增加"切面"可以使代码更清晰并且具有可维护性.但是AOP通常都依赖于第三方类库或者硬编码的.net特性来工作.虽然这些实现 ...

  6. how computer boot up?

    The power button activates the power supply in the PC, sending power to the motherboard and other co ...

  7. AS3.0中用于网络通信的类总结

      0条评论  1.Loader Loader 类可用于加载 SWF 文件或图像(JPG.PNG 或 GIF)文件.也只能是这些对象. 网络协议基础:HTTP/RTMP 加载方法原型:Loader.l ...

  8. ios中的关键词retain release

    内存分析  在函数中只要用new  alloc  copy  这样的分配空间时 则计算器retain就要为一 每调用一次就要加一 在.m文件中引用手动计数时 一定要调用[super dealloc]这 ...

  9. 解决oracle数据库连接不上的问题

    今天打开部署好的java开发的网站系统,反应好慢,第一反应就是后台有问题. 查看tomcat一堆的报错信息,重启还是存在. 使用plSql连接数据库看看,登录提示如下:ORA-12514:TNS:监听 ...

  10. 常用的opengl函数(三)

    glBlendFunc 定义像素算法.   void WINAPI glBlendFunc(GLenum sfactor,GLenum dfactor); 参数编辑 sfactor 指定红绿蓝和 al ...