。它今天發生在我身上。我只是用它做了一些小測試,但它不起作用。這裏是代碼:
static class TesteP {
private String a;
private String b;
private String c;
public String getA() {
return this.a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return this.b;
}
public void setB(String b) {
this.b = b;
}
public String getC() {
return this.c;
}
public void setC(String c) {
this.c = c;
}
@Override
public String toString() {
return new ToStringBuilder(this.getClass()).add("a", this.a).add("b", this.b).toString();
}
}
static class RestP {
private String a;
public String getA() {
return this.a;
}
public void setA(String a) {
this.a = a;
}
@Override
public String toString() {
return this.a;
}
}
public static void main(String[] args)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
TesteP p = new TesteP();
p.setA("AAAA");
p.setB("BBB");
TesteP pp = new TesteP();
RestP p2 = new RestP();
p2.setA("aaaa");
PropertyUtils.copyProperties(p,p2);
}
它解決了這個問題,使公開課程。也許你的一個班級不公開。這裏是我的情況下的解決方案:
public static class TesteP {
private String a;
private String b;
private String c;
public String getA() {
return this.a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return this.b;
}
public void setB(String b) {
this.b = b;
}
public String getC() {
return this.c;
}
public void setC(String c) {
this.c = c;
}
@Override
public String toString() {
return new ToStringBuilder(this.getClass()).add("a", this.a).add("b", this.b).toString();
}
}
public static class RestP {
private String a;
public String getA() {
return this.a;
}
public void setA(String a) {
this.a = a;
}
@Override
public String toString() {
return this.a;
}
}
public static void main(String[] args)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
TesteP p = new TesteP();
p.setA("AAAA");
p.setB("BBB");
TesteP pp = new TesteP();
RestP p2 = new RestP();
p2.setA("aaaa");
PropertyUtils.copyProperties(p,p2);
}
您是否升級到更新版本的beanutils?你能否將你的代碼恢復到較早的版本以找出改變了什麼? – Gray
@格雷 - 我沒有改變beanutils版本......我不確定是什麼讓它停止工作。當我試圖單獨重現問題時,它立即複製 - 所以現在我實際上不確定是什麼使它起作用。看看我的回答:http://stackoverflow.com/a/8385725/11236 – ripper234