Spring IOC类结构
2021-04-20 13:04:56 15 举报
Spring IOC类结构
作者其他创作
大纲/内容
Abstract class AbstractApplicationContext
+ refresh()
InterfaceAliasRegistry
+ registerAlias
Class DefaultListableBeanFactory
+ beanDefinitionMap
InterfaceApplicationContext
+
Class AnnotationConfigApplicationContext
+ reader:AnnotatedBeanDefinitionReader+ scanner:ClassPathBeanDefinitionScanner
Class GenericApplicationContext
+ beanFactory: DefaultListableBeanFactory+ resourceLoader: ResourceLoader+ refreshed : AtomicBoolean
Interface[ ]
InterfaceBeanDefinitionRegistry
+ registerBeanDefinition+ getBeanDefinition
Abstract Class AbstractBeanFactory
+ mergedBeanDefinitions+ alreadyCreated
+ doGetBean()+ createBean()
Class DefaultSingletonBeanRegistry
+ singletonObjects+ singletonFactories
doGetBean方法1. beanName创建RootBeanDefinition2.如果是singleton,创建createBeanInstance3. addSingletonFactory方法把bean实例添加到单例工厂4. 从singletonFactory中取出该bean 对象放入singletonObjects
Class ClassPathBeanDefinitionScanner
+ registry:BeanDefinitionRegistry
Spring 启动,1. 先创建ApplicationContext的实现类。有XML配置方式,有Annotation配置方式。ClassPathResourceScanner等。2. ApplicationContext的实现类会去引用DefaultListableBeanFactory 的 registerBeanDefinition方法创建BeanDefinition并放入Map集合。3. 完成BeanDefinitionMap的封装后,会调用AbstractApplicationContext的refresh方法,这里会根据beanDefinitionMap创建bean示例。4. 单例非懒加载的bean会先放入singletonObjects中
Abstract Class AbstractAutowireCapableBeanFactory
+ createBean()+ doCreateBean+ createBeanInstance+ instantiateBean
Class AnnotatedBeanDefinitionReader
+ registerBean(Class annotatedClass)
0 条评论
回复 删除
下一页