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 5348 MZL's endless loop

    乱搞题...第一直觉是混合图的欧拉通路,但是感觉并没有多大关系.最终AC的做法是不断的寻找欧拉通路,然后给边标号.所有边访问了一遍,所有点访问了一遍,效率是o(n+m).不存在-1的情况. #incl ...

  2. MySQL忘记密码解决办法

    一.windows下mysql忘记root密码的解决方法 详细出处参考:http://www.jb51.net/article/21984.htm 1,停止MYSQL服务,CMD打开DOS窗口,输入 ...

  3. WIN7 64位 IE10打开WEB管理提示证书不安全

    用IE10只要在CMD里运行 certutil -setreg chain\minRSAPubKeyBitLength 512 就好了

  4. leetcode136 利用异或运算找不同的元素

    Given an array of integers, every element appears twice except for one. Find that single one. Note: ...

  5. Git的安装

    两种方法: 1.命令行git Git preview是命令行Git的安装包,包名如下: Git-1.9.2-preview20140411.exe 2.UI类型的git 图形化界面的git,避免了枯燥 ...

  6. PHP数据库扩展mysqli的函数试题

    1.mysqli链接数据库的方式是什么? 2.mysqli获取链接错误号的属性是什么? 3.mysqli获取链接错误信息的属性是什么? 4.mysqli执行sql语句的函数是什么? 5.mysqli获 ...

  7. 在调试安卓系统的时候需要这个 ”adb disable-verity“

    在调试设备的时候.想要对文件进行读写 于是使用adb remount 出现提示. 请使用 ”adb  disable-verity“ 于是使用adb  disable-verity 的命令. 得到如下 ...

  8. jarsigner

    开发者应用认领说明 Flyme应用中心应用认领,采用Android的apk安装包签名机制来完成.如果你不清楚签名是什么,请联系开发人员协助您. 在Android平台发布应用程序之前,必须经过一个签名流 ...

  9. 登录数据库后,use db很慢的问题

    mysql> use dbl Reading table information for completion of table and column names You can turn of ...

  10. Ant 参考

    http://ant.apache.org/manual/Tasks/exec.html Exec Description Executes a system command. When the os ...