Spring factory.getBean(name)过程

Eagerly check singleton cache for manually registered singletons
check if bean definition exists in this factory
Not fond ->check parent factory
Guarantee initialization of beans that the current bean depends on.//保证当前bean所依赖的bean必须初始化完成
getBean(dependsOnBean)
if the current bean is singleton ,create bean instance and register it
else if the merged bean is prototype, create new bean directly without registering
else create bean by another custom scope, out of box the web springframework  supports exactly five scopes.
etc. singleton,prototype,request,session,globalSession,application,and a CustomScopeProcessor Class of SimpleThreadScope
 
about "create bean"
give BeanPostProcessor a chance to return a proxy instead of the target bean instance
InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation(beanClass, beanName)//比如:抑制目标对象的实例化,返回自己的一个对象。
Create a new instance using a appropriate instantiation strategy:factory method, autowire constructor, constructor, or simple instantiation. return BeanWrapper//作用是属性的访问,属性设置,属性类型转换。比如ResourceEditor可以将<property name="resource" value="/message.properties"/>转化为Resource resource。可以通过CustomEditorConfigurer将自己定制的转换器设置进去
Allow post-process to modify the merged bean definitions // MergedBeanDefinitionPostProcessor  收集bean类型里的Annotation,将其缓存在该processor中,在后面会用它来执行注入
Eagerly cache singletons to be able to resolve circular references // singletonsCurrentlyInCreation.add(A)  A->B   B->A  
populate the bean Instance in the given BeanWrapper with the property values  //填充属性值到bean实例。分别执行:InstantiationAwareBeanPostProcessor.postProcessAfterInstantiation 和 InstantiationAwareBeanPostProcessor.postProcessPropertyValues (比如:将@Autoware,@Required,@Resource属性设置进实例)
initialize the bean instance : invoke aware method(往bean注入beanName, classLoader, beanFactory),BeanPostProcessor.postProcessorBeforeInitialization (最主要的一个例子就是ApplicationContextAwareProcessor,它提供了ResourceLoader,EventPublisher,ApplicationContext等)
invoke afterPropertiesSet and init method
BeanPostProcessor.postProcessorAfterInitialization(BeanNameAutoProxyCreator根据BeanNames判断是否代理)
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值