commit 83d437de2ddeb877e4ca5fc48dc9dd07107e0d4a Author: hcd Date: Mon Oct 10 11:51:33 2022 +0800 init diff --git a/spring/笔记/笔记.txt b/spring/笔记/笔记.txt new file mode 100644 index 0000000..d75801e --- /dev/null +++ b/spring/笔记/笔记.txt @@ -0,0 +1,78 @@ +ClassPathXmlApplicationContext: + super(parent);// 调用父类构造方法,进行相关的对象创建等操作,包含属性的赋值操作 + setConfigLocations(configLocations);//设置应用程序上下文的配置路径 + refresh();//13个核心方法 + + /** + * 前戏,做容器刷新前的准备工作 + * 1、设置容器的启动时间 + * 2、设置活跃状态为true + * 3、设置关闭状态为false + * 4、获取Environment对象,并加载当前系统的属性值到Environment对象中 + * 5、准备监听器和事件的集合对象,默认为空的集合 + + * 备注: + * 准备过程中可以通过实现接口和子类继承做增强工作,修改一些配置,类似于AOP + */ + prepareRefresh(); + + // Tell the subclass to refresh the internal bean factory. + // 创建容器对象:DefaultListableBeanFactory + // 加载xml配置文件的属性值到当前工厂中,最重要的就是BeanDefinition + /**************************************************************************/ //备注: + /*ClassPathXmlApplicationContext重载了多个方法,传不同的参有不同的实现且过程中有环**境变量的替换还可以设置是否循环依赖和是否可以覆盖,修改方法通过集成空的父类重写方法*实现 + *例如MyClassPathXmlApplicationContext extends ClassPathXmlApplicationContext + *重写方法 + *解析过程(loadBeanDefinitions/重载比较多,就是用于解析配置文件的) + *ClassPathXmlApplicationContext(String[])传入的是string数组 + *String[]-String-resource[]-resource + *通过resource获取文档document并获取跟节点,循环遍历子节点 + *遍历过程中判断默认命名空间和自定义命名空间进行不同的处理方式解析 + */ + ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); + + // Prepare the bean factory for use in this context. + // beanFactory的准备工作,对各种属性进行填充 + prepareBeanFactory(beanFactory); + + try { + // Allows post-processing of the bean factory in context subclasses. + // 子类覆盖方法做额外的处理,此处我们自己一般不做任何扩展工作,但是可以查看web中的代码,是有具体实现的 + postProcessBeanFactory(beanFactory); + + // Invoke factory processors registered as beans in the context. + // 调用各种beanFactory处理器 + invokeBeanFactoryPostProcessors(beanFactory); + + // Register bean processors that intercept bean creation. + // 注册bean处理器,这里只是注册功能,真正调用的是getBean方法 + registerBeanPostProcessors(beanFactory); + + // Initialize message source for this context. + // 为上下文初始化message源,即不同语言的消息体,国际化处理,在springmvc的时候通过国际化的代码重点讲 + initMessageSource(); + + // Initialize event multicaster for this context. + // 初始化事件监听多路广播器 + initApplicationEventMulticaster(); + + // Initialize other special beans in specific context subclasses. + // 留给子类来初始化其他的bean + onRefresh(); + + // Check for listener beans and register them. + // 在所有注册的bean中查找listener bean,注册到消息广播器中 + registerListeners(); + + // Instantiate all remaining (non-lazy-init) singletons. + // 初始化剩下的单实例(非懒加载的) + finishBeanFactoryInitialization(beanFactory); + + // Last step: publish corresponding event. + // 完成刷新过程,通知生命周期处理器lifecycleProcessor刷新过程,同时发出ContextRefreshEvent通知别人 + finishRefresh(); + } + + + + \ No newline at end of file