日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring源码解析-实例化bean对象

發布時間:2023/12/2 javascript 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring源码解析-实例化bean对象 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  

  spring加載配置文件,AbstractApplicationContext類中的refresh方法起著重要的作用。

@Overridepublic void refresh() throws BeansException, IllegalStateException {synchronized (this.startupShutdownMonitor) {// Prepare this context for refreshing.準備刷新context prepareRefresh();// Tell the subclass to refresh the internal bean factory.刷新子類beanFactory,注冊beanDefinitionConfigurableListableBeanFactory 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. postProcessBeanFactory(beanFactory);// Invoke factory processors registered as beans in the context. invokeBeanFactoryPostProcessors(beanFactory);// Register bean processors that intercept bean creation. registerBeanPostProcessors(beanFactory);// Initialize message source for this context. initMessageSource();// Initialize event multicaster for this context. initApplicationEventMulticaster();// Initialize other special beans in specific context subclasses. onRefresh();// Check for listener beans and register them. registerListeners();// Instantiate all remaining (non-lazy-init) singletons.初始化非懶加載的bean實例 finishBeanFactoryInitialization(beanFactory);// Last step: publish corresponding event. finishRefresh();}catch (BeansException ex) {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;}}}

實例化bean對象,主要的是在

finishBeanFactoryInitialization(beanFactory)

?方法。
大致的流程圖(下部分):

?

(點擊查看大圖)

下面分析實例化bean對象的源碼分析

加載bean對象:

?

AbstractBeanFactory類中,根據不同scope進行實例化,例如Singleton,Prototype

?

?

?

?

?

?

根據不同情況采用不同的代理方式:

到這里就是bean實例的初始化,可以看到spring采用的代理方式,來實現bean的初始化。

?

轉載于:https://www.cnblogs.com/lzeffort/p/7669150.html

總結

以上是生活随笔為你收集整理的Spring源码解析-实例化bean对象的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。