0
点赞
收藏
分享

微信扫一扫

Spring的BeanPostProcessor扩展点实现类AutowiredAnnotationBeanPostProcessor

诗远 2022-01-26 阅读 76
springjava

实现Spring自动注入依赖的功能,在bean实例化后,进行这重要的初始化操作。

public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter implements MergedBeanDefinitionPostProcessor, PriorityOrdered, BeanFactoryAware {}

postProcessPropertyValues

	@Deprecated
	@Override
	public PropertyValues postProcessPropertyValues(
			PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) {

		return postProcessProperties(pvs, bean, beanName);
	}

postProcessProperties

对所有字段和方法,进行注入

public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) {
   InjectionMetadata metadata = findAutowiringMetadata(beanName, bean.getClass(), pvs);
   try {
      metadata.inject(bean, beanName, pvs);
   }
   catch (BeanCreationException ex) {
      throw ex;
   }
   catch (Throwable ex) {
      throw new BeanCreationException(beanName, "Injection of autowired dependencies failed", ex);
   }
   return pvs;
}
举报

相关推荐

0 条评论