1 Star 0 Fork 156

小风 / Spring-Analysis

forked from huifer / Code-Analysis 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Spring-ExtendedBeanInfoFactory.md 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
huifer 提交于 2020-11-25 11:17 . fix: 修正路径

Spring ExtendedBeanInfoFactory

  • 类全路径: org.springframework.beans.ExtendedBeanInfoFactory

ExtendedBeanInfo 作为BeanInfoFactory的实现, 主要目的和接口BeanInfoFactory一样. 返回一个 BeanInfo 接口对象. 接下来我们对这个方法进行分析

方法分析

getBeanInfo

getBeanInfo 详情
	@Override
	@Nullable
	public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
		return (supports(beanClass) ? new ExtendedBeanInfo(Introspector.getBeanInfo(beanClass)) : null);
	}

getBeanInfo 中出现了 supports来判断是否支持创建BeanInfo接口. 以及一个 BeanInfo接口的实现类ExtendedBeanInfo 有关 ExtendedBeanInfo 可以查看: 这篇文章

supports

supports 详情
	private boolean supports(Class<?> beanClass) {
		for (Method method : beanClass.getMethods()) {
			if (ExtendedBeanInfo.isCandidateWriteMethod(method)) {
				return true;
			}
		}
		return false;
	}

supports 出现的判断依据是 org.springframework.beans.ExtendedBeanInfo.isCandidateWriteMethod 起作用是判断是否可写. 即 set 方法

supports 详情
public static boolean isCandidateWriteMethod(Method method) {
		String methodName = method.getName();
		int nParams = method.getParameterCount();
		return (methodName.length() > 3 && methodName.startsWith("set") && Modifier.isPublic(method.getModifiers()) &&
				(!void.class.isAssignableFrom(method.getReturnType()) || Modifier.isStatic(method.getModifiers())) &&
				(nParams == 1 || (nParams == 2 && int.class == method.getParameterTypes()[0])));
	}
Java
1
https://gitee.com/jsfen/spring-analysis.git
git@gitee.com:jsfen/spring-analysis.git
jsfen
spring-analysis
Spring-Analysis
master

搜索帮助