SpringMVC容器初始化篇----ContextLoaderListener

Spring的监听器ContextLoaderListener的作用 立即下载

学习学习容器初始化,若有不对的地方,请指出更正,大家共同学习学习。

此篇幅主要围绕着 ContextLoaderListener加载容器,理解其中的原理。

ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息。

因为它实现了ServletContextListener这个接口,在web.xml配置这个监听器,启动容器时,就会默认执行它实现的方法。

ContextLoaderListener启动的上下文为根上下文,DispatcherServlet所创建的上下文的的父上下文即为此根上下文,可在FrameworkServlet中的initWebApplicationContext中看出。


通常在web.xml中如下配置:

[html]  view plain  copy
  1. <context-param>  
  2.         <param-name>contextConfigLocation</param-name>  
  3.         <param-value>classpath*:server_spring.xml  
  4.         </param-value>  
  5.     </context-param>  
  6.     <listener>  
  7.         <listener-class>org.springframework.web.context.ContextLoaderListener  
  8.         </listener-class>  
  9.     </listener>  


层次结构

                 
    

ContextLoaderListener继承ContextLoader类实现ServletContextListener接口
其中它的主要功能是在ContextLoader中实现,ServletContextListener接口在package javax.servlet中以为servlet的api,
ServletContextListener又继承EventListener,此乃package java.util;中的接口了。
EventListener接口中无任何方法。
ServletContextListener中含有2方法,一个初始化一个销毁。
[java]  view plain  copy
  1. /** 
  2.      * Receives notification that the web application initialization 
  3.      * process is starting. 
  4.      * 
  5.      * <p>All ServletContextListeners are notified of context 
  6.      * initialization before any filters or servlets in the web 
  7.      * application are initialized. 
  8.      * 
  9.      * @param sce the ServletContextEvent containing the ServletContext 
  10.      * that is being initialized 
  11.      */  
  12.     public void contextInitialized(ServletContextEvent sce);  
  13.   
  14.     /** 
  15.      * Receives notification that the ServletContext is about to be 
  16.      * shut down. 
  17.      * 
  18.      * <p>All servlets and filters will have been destroyed before any 
  19.      * ServletContextListeners are notified of context 
  20.      * destruction. 
  21.      * 
  22.      * @param sce the ServletContextEvent containing the ServletContext 
  23.      * that is being destroyed 
  24.      */  
  25.     public void contextDestroyed(ServletContextEvent sce);  


ContextLoaderListener初始化容器时序图


在ContextLoaderListener中的contextInitialized方法
[java]  view plain  copy
  1. /** 
  2.      * Initialize the root web application context. 
  3.      */  
  4.     @Override  
  5.     public void contextInitialized(ServletContextEvent event) {  
  6.         initWebApplicationContext(event.getServletContext());  
  7.     }  

初始化root跟web上下文,initWebApplicationContext方法在其父类ContextLoader中提供实现。

ContextLoader中initWebApplicationContext方法初始化根上下文
[java]  view plain  copy
  1. /** 
  2.      * Initialize Spring's web application context for the given servlet context, 
  3.      * using the application context provided at construction time, or creating a new one 
  4.      * according to the "{@link #CONTEXT_CLASS_PARAM contextClass}" and 
  5.      * "{@link #CONFIG_LOCATION_PARAM contextConfigLocation}" context-params. 
  6.      * @param servletContext current servlet context 
  7.      * @return the new WebApplicationContext 
  8.      * @see #ContextLoader(WebApplicationContext) 
  9.      * @see #CONTEXT_CLASS_PARAM 
  10.      * @see #CONFIG_LOCATION_PARAM 
  11.      */  
  12.     public WebApplicationContext initWebApplicationContext(ServletContext servletContext) {  
  13.         //这里判断是否在ServletContext中存在上下文,如果有,说明已载入过或配置文件出错,可以从错误信息中看出  
  14.         if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != ) {  
  15.             throw new IllegalStateException(  
  16.                     "Cannot initialize context because there is already a root application context present - " +  
  17.                     "check whether you have multiple ContextLoader* definitions in your web.xml!");  
  18.         }  
  19.   
  20.         Log logger = LogFactory.getLog(ContextLoader.class);  
  21.         servletContext.log("Initializing Spring root WebApplicationContext");  
  22.         if (logger.isInfoEnabled()) {  
  23.             logger.info("Root WebApplicationContext: initialization started");  
  24.         }  
  25.         long startTime = System.currentTimeMillis();  
  26.   
  27.         try {  
  28.             // Store context in local instance variable, to guarantee that  
  29.             // it is available on ServletContext shutdown.  
  30.             if (this.context == ) {  
  31.                 this.context = createWebApplicationContext(servletContext);  
  32.             }  
  33.             if (this.context instanceof ConfigurableWebApplicationContext) {  
  34.                 ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context;  
  35.                 if (!cwac.isActive()) {  
  36.                     // The context has not yet been refreshed -> provide services such as  
  37.                     // setting the parent context, setting the application context id, etc  
  38.                     if (cwac.getParent() == ) {  
  39.                         // The context instance was injected without an explicit parent ->  
  40.                         // determine parent for root web application context, if any.  
  41.                         // 这里载入根上下文的父上下文     
  42.                         ApplicationContext parent = loadParentContext(servletContext);  
  43.                         cwac.setParent(parent);  
  44.                     }  
  45.                      //这里从web.xml中取得相关的初始化参数,对WebApplicationContext进行初始化  
  46.                     configureAndRefreshWebApplicationContext(cwac, servletContext);  
  47.                 }  
  48.             }  
  49.             servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);  
  50.   
  51.             ClassLoader ccl = Thread.currentThread().getContextClassLoader();  
  52.             if (ccl == ContextLoader.class.getClassLoader()) {  
  53.                 currentContext = this.context;  
  54.             }  
  55.             else if (ccl != ) {  
  56.                 currentContextPerThread.put(ccl, this.context);  
  57.             }  
  58.   
  59.             if (logger.isDebugEnabled()) {  
  60.                 logger.debug("Published root WebApplicationContext as ServletContext attribute with name [" +  
  61.                         WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]");  
  62.             }  
  63.             if (logger.isInfoEnabled()) {  
  64.                 long elapsedTime = System.currentTimeMillis() - startTime;  
  65.                 logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");  
  66.             }  
  67.   
  68.             return this.context;  
  69.         }  
  70.         catch (RuntimeException ex) {  
  71.             logger.error("Context initialization failed", ex);  
  72.             servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);  
  73.             throw ex;  
  74.         }  
  75.         catch (Error err) {  
  76.             logger.error("Context initialization failed", err);  
  77.             servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err);  
  78.             throw err;  
  79.         }  
  80.     }  

根据提供的servlet上下文去初始化Spring的web应用上下文,在构造时使用当前应用上下文或者在web.xml中配置参数contextClass和contextConfigLocation去创建新的上下文。

先判断是否在ServletContext中存在root上下文,如果有,说明已载入过或配置文件出错,可以从错误信息中看出。
通过createWebApplicationContext方法创建web应用上下文,此上下文必定是实现了ConfigurableWebApplicationContext接口,在设置parent for root web application context,在configureAndRefreshWebApplicationContext方法里构造bean工厂和容器里bean的创建,这里就不描述了,下次专门研究这块,最后将跟上下文存入servletContext里,同时根web应用上下文存入到currentContextPerThread,可供后续取出当前上下文,currentContextPerThread = new ConcurrentHashMap<ClassLoader, WebApplicationContext>(1);。

ContextLoader中createWebApplicationContext方法创建根上下文
[java]  view plain  copy
  1. /** 
  2.      * Instantiate the root WebApplicationContext for this loader, either the 
  3.      * default context class or a custom context class if specified. 
  4.      * <p>This implementation expects custom contexts to implement the 
  5.      * {@link ConfigurableWebApplicationContext} interface. 
  6.      * Can be overridden in subclasses. 
  7.      * <p>In addition, {@link #customizeContext} gets called prior to refreshing the 
  8.      * context, allowing subclasses to perform custom modifications to the context. 
  9.      * @param sc current servlet context 
  10.      * @return the root WebApplicationContext 
  11.      * @see ConfigurableWebApplicationContext 
  12.      */  
  13.     protected WebApplicationContext createWebApplicationContext(ServletContext sc) {  
  14.         //这里需要确定我们载入的根WebApplication的类型,  
  15.         //由在web.xml中配置的contextClass中配置的参数, 如果没有使用默认的。   
  16.         Class<?> contextClass = determineContextClass(sc);  
  17.         //contextClass必须实现ConfigurableWebApplicationContext,否则抛异常  
  18.         if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {  
  19.             throw new ApplicationContextException("Custom context class [" + contextClass.getName() +  
  20.                     "] is not of type [" + ConfigurableWebApplicationContext.class.getName() + "]");  
  21.         }  
  22.         //初始化WebApplication,强转成ConfigurableWebApplicationContext  
  23.         return (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);  
  24.     }  

初始化根上下文,
最后返回值需强转成ConfigurableWebApplicationContext。

ContextLoader中determineContextClass方法找到根上下文的Class类型
[java]  view plain  copy
  1. /** 
  2.      * Return the WebApplicationContext implementation class to use, either the 
  3.      * default XmlWebApplicationContext or a custom context class if specified. 
  4.      * @param servletContext current servlet context 
  5.      * @return the WebApplicationContext implementation class to use 
  6.      * @see #CONTEXT_CLASS_PARAM 
  7.      * @see org.springframework.web.context.support.XmlWebApplicationContext 
  8.      */  
  9.     protected Class<?> determineContextClass(ServletContext servletContext) {  
  10.         String contextClassName = servletContext.getInitParameter(CONTEXT_CLASS_PARAM);  
  11.         if (contextClassName != ) {  
  12.             try {  
  13.                 return ClassUtils.forName(contextClassName, ClassUtils.getDefaultClassLoader());  
  14.             }  
  15.             catch (ClassNotFoundException ex) {  
  16.                 throw new ApplicationContextException(  
  17.                         "Failed to load custom context class [" + contextClassName + "]", ex);  
  18.             }  
  19.         }  
  20.         else {  
  21.             contextClassName = defaultStrategies.getProperty(WebApplicationContext.class.getName());  
  22.             try {  
  23.                 return ClassUtils.forName(contextClassName, ContextLoader.class.getClassLoader());  
  24.             }  
  25.             catch (ClassNotFoundException ex) {  
  26.                 throw new ApplicationContextException(  
  27.                         "Failed to load default context class [" + contextClassName + "]", ex);  
  28.             }  
  29.         }  
  30.     }  
Web.xml中配置了contextClass就取其值,但必须是实现ConfigurableWebApplicationContext,
没有的就取默认值XmlWebApplicationContext。

ContextClass默认值和ContextLoader.properties如下:

[java]  view plain  copy
  1. /** 
  2.      * Name of the class path resource (relative to the ContextLoader class) 
  3.      * that defines ContextLoader's default strategy names. 
  4.      */  
  5.     private static final String DEFAULT_STRATEGIES_PATH = "ContextLoader.properties";  
  6.   
  7.   
  8.     private static final Properties defaultStrategies;  
  9.   
  10.     static {  
  11.         // Load default strategy implementations from properties file.  
  12.         // This is currently strictly internal and not meant to be customized  
  13.         // by application developers.  
  14.         try {  
  15.             ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, ContextLoader.class);  
  16.             defaultStrategies = PropertiesLoaderUtils.loadProperties(resource);  
  17.         }  
  18.         catch (IOException ex) {  
  19.             throw new IllegalStateException("Could not load 'ContextLoader.properties': " + ex.getMessage());  
  20.         }  
  21.     }  

[plain]  view plain  copy
  1. # Default WebApplicationContext implementation class for ContextLoader.  
  2. # Used as fallback when no explicit context implementation has been specified as context-param.  
  3. # Not meant to be customized by application developers.  
  4.   
  5. org.springframework.web.context.WebApplicationContext=org.springframework.web.context.support.XmlWebApplicationContext  


其中loadParentContext
[java]  view plain  copy
  1. /** 
  2.      * Template method with default implementation (which may be overridden by a 
  3.      * subclass), to load or obtain an ApplicationContext instance which will be 
  4.      * used as the parent context of the root WebApplicationContext. If the 
  5.      * return value from the method is null, no parent context is set. 
  6.      * <p>The main reason to load a parent context here is to allow multiple root 
  7.      * web application contexts to all be children of a shared EAR context, or 
  8.      * alternately to also share the same parent context that is visible to 
  9.      * EJBs. For pure web applications, there is usually no need to worry about 
  10.      * having a parent context to the root web application context. 
  11.      * <p>The default implementation uses 
  12.      * {@link org.springframework.context.access.ContextSingletonBeanFactoryLocator}, 
  13.      * configured via {@link #LOCATOR_FACTORY_SELECTOR_PARAM} and 
  14.      * {@link #LOCATOR_FACTORY_KEY_PARAM}, to load a parent context 
  15.      * which will be shared by all other users of ContextsingletonBeanFactoryLocator 
  16.      * which also use the same configuration parameters. 
  17.      * @param servletContext current servlet context 
  18.      * @return the parent application context, or {@code null} if none 
  19.      * @see org.springframework.context.access.ContextSingletonBeanFactoryLocator 
  20.      */  
  21.     protected ApplicationContext loadParentContext(ServletContext servletContext) {  
  22.         ApplicationContext parentContext = ;  
  23.         String locatorFactorySelector = servletContext.getInitParameter(LOCATOR_FACTORY_SELECTOR_PARAM);  
  24.         String parentContextKey = servletContext.getInitParameter(LOCATOR_FACTORY_KEY_PARAM);  
  25.   
  26.         if (parentContextKey != ) {  
  27.             // locatorFactorySelector may be null, indicating the default "classpath*:beanRefContext.xml"  
  28.             BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator.getInstance(locatorFactorySelector);  
  29.             Log logger = LogFactory.getLog(ContextLoader.class);  
  30.             if (logger.isDebugEnabled()) {  
  31.                 logger.debug("Getting parent context definition: using parent context key of '" +  
  32.                         parentContextKey + "' with BeanFactoryLocator");  
  33.             }  
  34.             this.parentContextRef = locator.useBeanFactory(parentContextKey);  
  35.             parentContext = (ApplicationContext) this.parentContextRef.getFactory();  
  36.         }  
  37.   
  38.         return parentContext;  
  39.     }  

根据在web.xml中配置的locatorFactorySelector和parentContextKey来给根web应用上下设置父上下文,如果没配置的话,父上下文为空。
加载父上下文的主要原因是允许多重root web application contexts作为可共享的ERA context的子节点,或者对EJB可见的去交替共享同样的父上下文。For pure web applications, there is usually no need to worry about having a parent context to the root web application context。这句话明确告诉我们,对于纯粹的Web应用,通常不用担心root web application context的父上下文,也就是没有,为null。

在应用程序如何获取 WebApplicationContext 有多种方式,最简单的就是

1.WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();

当前应用的WebApplicationContext就保存在 ContextLoader的currentContextPerThread属性当中


2.基于ServletContext上下文获取的方式

ServletContext sc = request.getSession().getServletContext();

ApplicationContext ac1 = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);

ApplicationContext ac2 = WebApplicationContextUtils.getWebApplicationContext(sc);

WebApplicationContext wac1 = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);


3.还有一些更合适的,基于Spring提供的抽象类或者接口,在初始化Bean时注入ApplicationContext

3.1:继承自抽象类ApplicationObjectSupport

说明:抽象类ApplicationObjectSupport提供getApplicationContext()方法,可以方便的获取到ApplicationContext。

Spring初始化时,会通过该抽象类的setApplicationContext(ApplicationContext context)方法将ApplicationContext 对象注入。


3.2:继承自抽象类WebApplicationObjectSupport

说明:类似上面方法,调用getWebApplicationContext()获取WebApplicationContext


3.3:实现接口ApplicationContextAware

说明:实现该接口的setApplicationContext(ApplicationContext context)方法,并保存ApplicationContext 对象。



总结:Context结构复杂,parentContext结构的作用,及如何的去加载bean工厂的逻辑原理。
SAP采购订单中项目类别B(限制)的控制逻辑 在笔者所在企业中,框架类采购订单中项目类别需要选择B(限制)。今天笔者从比较全面的角度分析了一下这个项目类别B到底可以决定些什么?控制到什么?先从后台SPRO中打开相应的配置菜单。 打开项目类别B之后,可以看到一些配置信息,这里有一点与其它配置不同的地方,即无法新增项目,也无法修改现有项目。这个疑惑今后再去解决吧。当前只研究项目类别B的控制逻辑。 下面就参考上图中的配置分段来分析和测试其控制逻辑, 1、如项目类别配置图,所需材料值为不允许;经测试,如下图在采购订单创建时,不能输入物料编号条目。 阅读详情

相关推荐

基于STM32的INA226电压电流检测仪

该功率检测装置以STM32F103C8T6微控制器为核心,集成功率检测、数据交互、状态显示和用户提示功能,通过模块化设计实现稳定运行。系统包括按键、LED指示灯、OLED屏幕、INA226电压电流检测、复位电路、晶振电路、蜂鸣器驱动、输入输出接口、调试接口和3.3V降压电路等模块。微控制器通过按键检测用户输入,启动功率检测,采集数据并通过OLED显示,异常情况触发蜂鸣器报警,LED状态指示同步反馈。3.3V降压电路为所有模块提供稳定电源,晶振电路确保时序精度。INA226芯片通过I2C接口与微控制器通信,实

a2784288164的博客 1912

ContextLoaderListener

SSM,ssm整合,ContextLoaderListener

weixin_60664694的博客 3751

《Kubernetes部署篇:基于x86_64+aarch64架构CPU+containerd一键离线部署容器版K8S1.33.3高可用集群》

《Kubernetes部署篇:基于x86_64+aarch64架构CPU+containerd一键离线部署容器版K8S1.33.3高可用集群》

东城绝神 1369

ContextLoaderListener解析

ContextLoaderListener解析~

walidake的博客 2237

Frigate进阶玩法:如何用MQTT和Python脚本扩展你的自定义目标检测算法

本文详细介绍了如何通过MQTT和Python脚本扩展Frigate的自定义目标检测算法,无需修改源码即可实现特殊场景(如工业设备异常、农业病虫害识别)的高效检测。文章涵盖Frigate配置、外部检测服务构建、高级集成技巧及性能优化实践,帮助开发者灵活扩展智能监控能力。

weixin_42662293的博客 350

卷积码和Turbo码

通信原理相关博文目录:目录我们常在移动通信中遇到的卷积码就是一种非分组码,卷积码和信号处理中的卷积运算有关系吗?是不是就是信号处理中的卷积运算,先看看编码器的编码原理再说:下面是一个比较实用的卷积码编码器:它有三个移位寄存器D0,D1,D2和三个模2加法器,以及一个旋转开关组成,编码前,先将各级移位寄存器清零:现在假设输入的信息码元是1101:当输入的第一个码元为1时,三个模2加法器计算的结果都为...

Reborn Lee 2万+

org.springframework.web.context.ContextLoaderListener

1、用法 ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息。因为它实现了ServletContextListener这个接口,在web.xml配置这个监听器,启动容器时,就会默认执行它实现的方法。至于ApplicationContext.xml这个配置文件部署在哪,如何配置多个xml文件,书上都没怎么详细说明。现在的

小飞侠的博客 3556

01. VBA从入门到精通——录制宏、窗口、快捷键

excel表功能区右击→常用→选择显示开发工具选项→确定Visual Basic:打开VBA窗口宏:查看要录制的宏录制宏:准备录制宏使用相对引用:录制宏的时候对单元格的引用做一个设置宏安全性:对宏的使用做安全设置,一般设置为禁用所有宏,并发出通知,此时打开带有宏代码的工作薄时会出现警告标记,如果宏可信就选择启动。

weixin_43812198的博客 1697

解决Tomcat启动时报org.springframework.web.context.ContextLoaderListener

项目为maven+spring+springmvc+mybatis 由于某一个操作, 我就是做了这个操作之后发现启动项目tomcat报错:org.springframework.web.context.ContextLoaderListener, 首先我分析,是不是maven依赖没有下载全,结果真的是少spring-context,然后改了一下pom保存一下,maven clean...

w的博客 4万+

手把手教你学Simulink--基于高频与高速信号处理的滤波器场景实例:毫米波雷达中匹配滤波器的多目标分辨仿真

在自动驾驶、智能交通和工业感知等领域,毫米波雷达(mmWave Radar)因其高分辨率全天候工作和抗电磁干扰能力,成为关键的感知传感器。其核心信号处理算法之一是匹配滤波器(Matched Filter),用于在强噪声背景下最大化信噪比(SNR),实现对微弱目标的检测。在调频连续波(FMCW, Frequency-Modulated Continuous Wave)雷达中,发射信号为线性调频(Chirp)信号。当信号遇到多个目标时,回波是多个延迟版本的叠加。

MHD0815的博客 135

SAP ABAP Append structure 介绍

所有在 append structure 上增强的字段都是 append structure 的一部分,这意味着对这些增强所做的任何更改仅仅施加在 append structure 上,而不会影响被增强的 ABAP DDIC 结构。这同样适用于 transport. 激活数据库表或结构时,会找到所有关联的 append structure,并将它们的组件附加到数据库表或结构。Append structure(附加结构)是 ABAP 字典中附加到另一个结构或数据库表并将其组件附加到它们的结构。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1166

SpringMVC解析(1)-容器初始化

Spring MVC(1) - 容器初始化 spring mvc 项目 web.xml <!-- Spring配置 会初始化一个Root Spring WebApplicationContext 容器 --> <!-- 在 Servlet 容器启动时(Tomcat、Jetty)会被 ContextLoaderListener 监听到,从而调用 #contextInitialized(ServletContextEvent event) 方法,初始化 Root WebApplication

lvoye的博客 286

使用C# HslCommunication库实现三菱PLC通信(含完整代码示例)

在工业自动化开发中,上位机与PLC的通信是关键环节。HslCommunication库是一个开源的.NET工业通信库,支持三菱、西门子、欧姆龙等多个品牌PLC的通信协议。本文将演示如何通过库实现C#程序与三菱PLC的通信,并提供完整的代码示例。

StevenChen的博客 2294

Spring MVC 初始化源码(1)—ContextLoaderListener监听器与父上下文容器的初始化

基于最新Spring 5.x,详细介绍了Spring MVC 初始化流程的源码,主要包括ContextLoaderListener与根上下文容器的初始化流程的源码,以及web.xml文件加载流程。

终生学习践行者 6293

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Spring源码学习:SpringMVC(1)根容器初始化

​ Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层。Servlet 是一个java 编写的程序,此程序基于http 协议,在服务端运行达到是按照servlet 规范编写的一个类。主要处理客户端的请求并将结果发送到客户端。​整个ContextLoaderListener类的启动过程到此就结束了,可以发现,创建是比较核心的一个步骤,主要工作就是为了创建根IoC容器。

small_kai的博客 1049

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Spring+SpringMVC项目中的容器初始化过程

而是因为Listener、Filter、Servlet是Web容器管理的,而bean是Spring容器或SpringMVC容器管理的。获取servlet节点信息,创建Servlet实例集合,其中的DispatcherServlet就是用来完成SpringMVC容器(XmlWebApplicationContext)初始化的;当执行SpringMVC容器的getBean方法在自己的context中找不到对应的bean,则会在父容器Spring容器的context中找对应的bean。至此,SSM项目启动完成。

2509_94228395的博客 814

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

SpringMVC源码-SpringMVC框架中Spring父容器和SpringMVC子容器加载的流程以及SpringMVC九大内置组件的初始

SpringMVC框架中Spring父容器和SpringMVC子容器加载的流程以及SpringMVC九大内置组件的初始

qq_37200262的博客 1167

SpringMVC之ContextLoaderListener

ContextLoaderListener的作用就是启动Web容器时自动装配ApplicationContext的配置信息。它实现了ServletContextListener接口,在web.xml中配置这个监听器,启动容器时就会执行它的实现类。 对于ServletContextListener,你可以利用它在为客户端请求提供服务之前像 向ServletContext中添加任意对象。该对象将在Se...

业精于勤荒于嬉 行成于思毁于随 1989
上一篇: 【Spring MVC学习】WebApplicationContext初始化的三种方式
下一篇: 浅谈 C/S 和 B/S 架构
ole_triangle_java
博客等级 码龄10年 82粉丝 83原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值