spring的beanutils工具类_基于spring-beans实现工具类BeanUtils基于Class实例化注入对象及查找方法、复制属性等操作...

一、前言

基于spring-beans(4.1.4)的工具类org.springframework.beans.BeanUtils对注入spring对象按照Class实例化instantiateClass、class对象方法名称methodName查找findMethod、属性查找对于class类信息findPropertyType、对象属性复制copyProperties等常用操作,具体如下源码所示。

二、源码说明package org.springframework.beans;@b@@b@import java.beans.PropertyDescriptor;@b@import java.beans.PropertyEditor;@b@import java.lang.reflect.Constructor;@b@import java.lang.reflect.InvocationTargetException;@b@import java.lang.reflect.Method;@b@import java.lang.reflect.Modifier;@b@import java.net.URI;@b@import java.net.URL;@b@import java.util.Arrays;@b@import java.util.Collections;@b@import java.util.Date;@b@import java.util.List;@b@import java.util.Locale;@b@import java.util.Set;@b@import org.apache.commons.logging.Log;@b@import org.apache.commons.logging.LogFactory;@b@import org.springframework.core.MethodParameter;@b@import org.springframework.util.Assert;@b@import org.springframework.util.ClassUtils;@b@import org.springframework.util.ConcurrentReferenceHashMap;@b@import org.springframework.util.ReflectionUtils;@b@import org.springframework.util.StringUtils;@b@@b@public abstract class BeanUtils@b@{@b@  private static final Log logger = LogFactory.getLog(BeanUtils.class);@b@  private static final Set> unknownEditorTypes = Collections.newSetFromMap(new ConcurrentReferenceHashMap(64));@b@@b@  public static  T instantiate(Class clazz)@b@    throws BeanInstantiationException@b@  {@b@    Assert.notNull(clazz, "Class must not be null");@b@    if (clazz.isInterface())@b@      throw new BeanInstantiationException(clazz, "Specified class is an interface");@b@    try@b@    {@b@      return clazz.newInstance();@b@    }@b@    catch (InstantiationException ex) {@b@      throw new BeanInstantiationException(clazz, "Is it an abstract class?", ex);@b@    }@b@    catch (IllegalAccessException ex) {@b@      throw new BeanInstantiationException(clazz, "Is the constructor accessible?", ex);@b@    }@b@  }@b@@b@  public static  T instantiateClass(Class clazz)@b@    throws BeanInstantiationException@b@  {@b@    Assert.notNull(clazz, "Class must not be null");@b@    if (clazz.isInterface())@b@      throw new BeanInstantiationException(clazz, "Specified class is an interface");@b@    try@b@    {@b@      return instantiateClass(clazz.getDeclaredConstructor(new Class[0]), new Object[0]);@b@    }@b@    catch (NoSuchMethodException ex) {@b@      throw new BeanInstantiationException(clazz, "N

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值