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. 《剑指Offer》算法题——替换空格

    题目:请实现一个函数,将一个字符串中的空格替换成“ % 20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are % 20Happy. class Solution ...

  2. undefine refrence to "*******"

    windows mingw gcc  编译出现莫名的错误  wsaaddresstostringa, 理解起来,应该是link的时候,出现的问题 (在console的日志栏也能看出来) 然后,在ECL ...

  3. OpenCV ——背景建模之CodeBook(2)

    1,CodeBook的来源 先考虑平均背景的建模方法.该方法是针对每一个像素,累积若干帧的像素值,然后计算平均值和方差,以此来建立背景模型,相当于模型的每一个像素含有两个特征值,这两个特征值只是单纯的 ...

  4. Hunters

    Hunters Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submi ...

  5. htop安装步骤【原创】

    htop安装步骤 下载:http://hisham.hm/htop/releases/ [root@hchtest2 ~]# tar zxvf htop-2.0.2.tar.gz [root@hcht ...

  6. 后台数据download成excel的方法(controller/action)

    jsp页面端 <a href="/portal/server/importExec" title="Data Download"> <img ...

  7. cmd命令行查看当前系统版本和版本是32位还是64位

  8. Linux 任务控制(bg job fg nohup &)

    一. 简介     Linux/Unix 区别于微软平台最大的优点就是真正的多用户,多任务.因此在任务管理上也有别具特色的管理思想.我们知道,在 Windows 上面,我们要么让一个程序作为服务在后台 ...

  9. Linux(centos5.0+)unison+inotify-tools触发式双向自动同步

    192.168.1.11是server1, 192.168.1.22是server2. [1]安装inotify-tools   各大linux发行版本都有inotify-tools软件包,建议通过y ...

  10. 二维 ST POJ 2019

    题目大意:给你一个n*n的矩阵,每次给你一个点(x,y),以其为左上角,宽度为b的矩阵中最小的数值和最大数值的差是多少?  一共k个询问. 思路:简单的二维st. 定义dp(i,j,k,L)表示以(i ...