国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Java Spring WEB應(yīng)用實(shí)例化如何實(shí)現(xiàn)

瀏覽:20日期:2022-08-20 08:23:15

1.前面講解的都是通過直接讀取配置文件,進(jìn)行的實(shí)例化ApplicationContext

AbstractApplicationContext app = new ClassPathXmlApplicationContext('beans.xml');

下面講解直接通過配置文件進(jìn)行初始化。

2.web.xml

<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:beans.xml</param-value></context-param><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>

這樣,ApplicationContext便已經(jīng)實(shí)例化了,默認(rèn)就直接加載了beans.xml里面的內(nèi)容。

來(lái)看看底層的代碼,類ContextLoaderListener中有個(gè)初始化方法

public void contextInitialized(ServletContextEvent event) { this.contextLoader = createContextLoader(); if (this.contextLoader == null) { this.contextLoader = this; } this.contextLoader.initWebApplicationContext(event.getServletContext()); }

進(jìn)入initWebApplicationContext方法 :

ApplicationContext parent = loadParentContext(servletContext); // Store context in local instance variable, to guarantee that // it is available on ServletContext shutdown. this.context = createWebApplicationContext(servletContext, parent);

這句也就是容器加載的結(jié)果。

1和2一個(gè)是java代碼一個(gè)是xml代碼,不過實(shí)現(xiàn)的效果都是一樣的。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 安溪县| 思茅市| 淅川县| 五原县| 玉树县| 纳雍县| 四平市| 习水县| 永平县| 高雄市| 三明市| 平凉市| 光泽县| 汉川市| 淅川县| 南陵县| 项城市| 玛纳斯县| 襄汾县| 唐山市| 壤塘县| 增城市| 扬州市| 蒲城县| 晋江市| 时尚| 沂源县| 綦江县| 兴和县| 新巴尔虎右旗| 青海省| 莱阳市| 金华市| 富源县| 华亭县| 荣成市| 漳浦县| 梁平县| 抚顺县| 河东区| 安岳县|