yidaixiaoxia1217
2014-04-24 13:43使用apache的BeanUtils,一个很诡异的问题
public class MyBeanUtils
extends org.apache.commons.beanutils.BeanUtils {
public static void copyBeanNotNull2Bean(Object databean,Object tobean)throws Exception
{
PropertyDescriptor origDescriptors[] =
PropertyUtils.getPropertyDescriptors(databean);
for (int i = 0; i < origDescriptors.length; i++) {
String name = origDescriptors[i].getName();
// String type = origDescriptors[i].getPropertyType().toString();
if ("class".equals(name)) {
continue; // No point in trying to set an object's class
}
if (PropertyUtils.isReadable(databean, name) &&
PropertyUtils.isWriteable(tobean, name)) {
try {
Object value = PropertyUtils.getSimpleProperty(databean, name);
if(value!=null){
copyProperty(tobean, name, value);
}
}
catch (java.lang.IllegalArgumentException ie) {
logger.error(ie,ie); // Should not happen
}
catch (Exception e) {
logger.error(e,e); // Should not happen
}
}
}
}
}
使用这段代码进行javabean的复制,并且srcBean为null的字段,不进行复制。
这段代码测试环境是正常的,在生产环境下,运行一段时间后(大概有1个月的样子),就会出现很诡异的问题,javaBean里面Integer,Long等类型的 复制后字段变成null了(源javaBean和目标javaBean该字段都不不为空的情况下)。
正在持续监测中...
注:copyProperty 方法是继承于org.apache.commons.beanutils.BeanUtils
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- eclipse使用debug模式启动web服务报错
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- cglib BeanGenerator 实例化无反应
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- SSH2框架配置问题
- ssh2
- 0个回答
- spring aop报错
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- rapid-framework 中Action中的Manager调用问题?
- spring
- hibernate
- 0个回答