要须心地收汗马,孔孟行世目杲杲。这篇文章主要讲述spring ApplicationContext中Bean的生命周期相关的知识,希望能为你提供帮助。
AbstractApplicationContext
Spring的AbstractApplicationContext是ApplicationContext的抽象实现类,该抽象类的refresh方法定义了spring容器在加载配置文件后的各项处理过程
文章图片
文章图片
public void refresh() throws BeansException, IllegalStateException { synchronized (this.startupShutdownMonitor) { prepareRefresh(); // 初始化BeanFactory ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); prepareBeanFactory(beanFactory); try { postProcessBeanFactory(beanFactory); /** *调用工厂后处理器: *根据反射机制找出所有实现了BeanFactoryPostProcessor接口的Bean, *并调用其postProcessBeanFactory()接口方法 */ invokeBeanFactoryPostProcessors(beanFactory); /** * 注册Bean后处理器: * 根据反射机制找出所有实现了BeanPostProcessor接口的Bean, * 并注册 */ registerBeanPostProcessors(beanFactory); // 初始化消息源:初始化容器的国际化消息资源 initMessageSource(); // 初始化Application事件广播器 initApplicationEventMulticaster(); // 初始化其他特殊的Bean,由具体子类实现 onRefresh(); // 注册事件监听器 registerListeners(); // 初始化所有单例的Bean,使用懒加载的除外 finishBeanFactoryInitialization(beanFactory); // Last step: publish corresponding event. finishRefresh(); } catch (BeansException ex) { if (logger.isWarnEnabled()) { logger.warn("Exception encountered during context initialization - " + "cancelling refresh attempt: " + ex); } // Destroy already created singletons to avoid dangling resources. destroyBeans(); // Reset ‘active‘ flag. cancelRefresh(ex); // Propagate exception to caller. throw ex; } finally { // Reset common introspection caches in Spring‘s core, since we // might not ever need metadata for singleton beans anymore... resetCommonCaches(); } } }
AbstractApplicationContext源码【spring ApplicationContext中Bean的生命周期】
推荐阅读
- 常见Failed to load ApplicationContext异常解决方案!!
- 蓝牙ble数据转语音实现Android AudioRecord方法推荐
- Appium中使用相对路径定位元素Xputh
- 不通过百川打开淘宝app
- Consider defining a bean of type 'com.lvjing.dao.DeviceStatusMapper' in your configuration.(
- Android控制双击返回按钮退出程序的代码
- 使用appium1.4在android8.0真机上测试程序时报错command failed shell "ps 'uiautomator'"的解决方式
- react_app 项目开发 _后台服务器端-node
- Android-Java-面向对象与面向过程的简单理解