久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

Java Spring WEB應用實例化如何實現

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

1.前面講解的都是通過直接讀取配置文件,進行的實例化ApplicationContext

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

下面講解直接通過配置文件進行初始化。

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便已經實例化了,默認就直接加載了beans.xml里面的內容。

來看看底層的代碼,類ContextLoaderListener中有個初始化方法

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

進入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);

這句也就是容器加載的結果。

1和2一個是java代碼一個是xml代碼,不過實現的效果都是一樣的。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Java
相關文章:
主站蜘蛛池模板: 墨竹工卡县| 江源县| 梓潼县| 神木县| 汾阳市| 黑河市| 菏泽市| 道孚县| 清远市| 灵川县| 寿宁县| 昌图县| 呼和浩特市| 徐州市| 大连市| 湘西| 黎平县| 嘉禾县| 嵊州市| 南华县| 宁乡县| 陈巴尔虎旗| 米易县| 贵港市| 沿河| 郑州市| 石城县| 屯昌县| 米易县| 巫溪县| 崇左市| 仙桃市| 汶川县| 汕尾市| 阳江市| 当涂县| 敦化市| 卓资县| 南投县| 九龙县| 逊克县|