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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

ApplicationContext容器的设计原理

發(fā)布時(shí)間:2023/12/20 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ApplicationContext容器的设计原理 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.在ApplicationContext容器中,我們以常用的FileSystemXmlApplicationContext實(shí)現(xiàn)為例來(lái)說(shuō)明ApplicationContext容器的設(shè)計(jì)原理

2.在FileSystemXmlApplicationContext的設(shè)計(jì)中,我們看到ApplicationContext應(yīng)用上下文的主要功能已經(jīng)在FileSystemXmlApplicationContext的基類AbstractXmlApplication中實(shí)現(xiàn)了,在FileSystemXmlApplicationContext中,作為一個(gè)具體的應(yīng)用上下文,只需要實(shí)現(xiàn)和它自身設(shè)計(jì)相關(guān)兩個(gè)功能

3.一個(gè)功能是,如果應(yīng)用直接使用FileSystemXmlApplicationContext,對(duì)于實(shí)例化這個(gè)應(yīng)用上下文支持同時(shí)啟動(dòng)IoC容器的refresh()過(guò)程。這在FileSystemXmlApplicationContext的代碼實(shí)現(xiàn)中可以看到,代碼如下:

?

1 /** 2 * Create a new FileSystemXmlApplicationContext with the given parent, 3 * loading the definitions from the given XML files. 4 * @param configLocations array of file paths 5 * @param refresh whether to automatically refresh the context, 6 * loading all bean definitions and creating all singletons. 7 * Alternatively, call refresh manually after further configuring the context. 8 * @param parent the parent context 9 * @throws BeansException if context creation failed 10 * @see #refresh() 11 */ 12 public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent) 13 throws BeansException { 14 15 super(parent); 16 setConfigLocations(configLocations); 17 if (refresh) { 18 refresh(); 19 } 20 } FileSystemXmlApplicationContext(String[] configLocations,boolean,ApplicationContext)

?

4.這個(gè)refresh()過(guò)程會(huì)牽涉IoC容器啟動(dòng)一系列復(fù)雜操作,同時(shí),對(duì)于不同的容器實(shí)現(xiàn),這些操作都是類似的,因此在基類中將它們封裝好。所以,我們?cè)贔ileSystemXmlApplicationContext的設(shè)計(jì)中看到的只是一個(gè)簡(jiǎn)單的調(diào)用。

5.另一功能是與FileSystemXmlApplicationContext設(shè)計(jì)具體相關(guān)的功能,這部分與怎樣從文件系統(tǒng)加載XML的Bean定義資源有關(guān)。

6.通過(guò)這個(gè)實(shí)現(xiàn),可以在文件系統(tǒng)中讀取以XML形式存在的BeanDefinition做準(zhǔn)備,因?yàn)椴煌膽?yīng)用上下文實(shí)現(xiàn)對(duì)應(yīng)著不同的讀取BeanDefinition的方式,在FileSystemXmlApplicationContext中的實(shí)現(xiàn)代碼如下:

?

1 /** 2 * Create a new FileSystemXmlApplicationContext with the given parent, 3 * loading the definitions from the given XML files. 4 * @param configLocations array of file paths 5 * @param refresh whether to automatically refresh the context, 6 * loading all bean definitions and creating all singletons. 7 * Alternatively, call refresh manually after further configuring the context. 8 * @param parent the parent context 9 * @throws BeansException if context creation failed 10 * @see #refresh() 11 */ 12 public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent) 13 throws BeansException { 14 15 super(parent); 16 setConfigLocations(configLocations); 17 if (refresh) { 18 refresh(); 19 } 20 } getResourceByPath

?可以看到,調(diào)用這個(gè)方法,可以得到FileSystemResource的資源定位。

轉(zhuǎn)載于:https://www.cnblogs.com/duffy/p/3953712.html

總結(jié)

以上是生活随笔為你收集整理的ApplicationContext容器的设计原理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。