Spring源码解析之BeanFactory

BeanFactory接口:

  用于访问SpringBean容器的根接口,这个接口是由持有许多bean定义的对象实现的,每个定义都由一个字符串名称唯一标识。根据bean定义,工厂将返回包含对象的独立实例(原型设计模式)或单个共享实例(与工厂范围内的单例实例为单例的单例设计模式相比,这是一种更好的选择)。BeanFactory是应用程序组件的中心注册表,并集中应用程序组件的配置。

完整的初始化方法及其标准顺序是:

1. BeanNameAware's setBeanName
2. BeanClassLoaderAware's setBeanClassLoader
3. BeanFactoryAware's setBeanFactory
4. ResourceLoaderAware's setResourceLoader (only applicable when running in an application context)
5. ApplicationEventPublisherAware's setApplicationEventPublisher (only applicable when running in an application context)
6. MessageSourceAware's setMessageSource (only applicable when running in an application context)
7. ApplicationContextAware's setApplicationContext (only applicable when running in an application context)
8. ServletContextAware's setServletContext (only applicable when running in a web application context)
9. postProcessBeforeInitialization methods of BeanPostProcessors
10. InitializingBean's afterPropertiesSet
11. a custom init-method definition
12. postProcessAfterInitialization methods of BeanPostProcessors

 

String[]getAliases(String name) 
          Return the aliases for the given bean name, if any.
<T> T
getBean(Class<T> requiredType) 
          Return the bean instance that uniquely matches the given object type, if any.
 ObjectgetBean(String name) 
          Return an instance, which may be shared or independent, of the specified bean.
<T> T
getBean(String name, Class<T> requiredType) 
          Return an instance, which may be shared or independent, of the specified bean.
 ObjectgetBean(String name, Object... args) 
          Return an instance, which may be shared or independent, of the specified bean.
 Class<?>getType(String name) 
          Determine the type of the bean with the given name.
 booleanisPrototype(String name) 
          Is this bean a prototype? That is, will getBean(java.lang.String) always return independent instances?
 booleanisSingleton(String name) 
          Is this bean a shared singleton? That is, will getBean(java.lang.String) always return the same instance?
 booleanisTypeMatch(String name, Class<?> targetType) 
          Check whether the bean with the given name matches the specified type.

转载于:https://www.cnblogs.com/yaohuiqin/p/10435356.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值