首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • Spring源码系列-容器刷新:wac.refresh

    在initWebApplicationContext方法是用来创建容器的,核心代码如下: 今天主要来看configureAndRefreshWebApplicationContext方法中最后的wac.refresh

    17600编辑于 2025-06-07
  • 来自专栏IT技术精选文摘

    深入分析Spring 与 Spring MVC容器

    = null) { wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + } wac.setParent(parent); wac.setServletContext(sc); //设置spring的配置文件 wac.setConfigLocation (sc.getInitParameter(CONFIG_LOCATION_PARAM)); customizeContext(sc, wac); //spring容器初始化 wac.refresh(); return wac; } ContextLoaderListener构建Root Context时序图: protected WebApplicationContext onRefresh(wac); } if (this.publishContext) { // Publish the context as a

    93960发布于 2018-01-30
  • 来自专栏java小白

    SpringMVC工作原理流程(一)

    (wac); return wac; } configureAndRefreshWebApplicationContext() protected void configureAndRefreshWebApplicationContext (ConfigurableWebApplicationContext wac){ if(ObjectUtils.identityToString(wac).equals(wac.getId =null){ wac.setId(this.contextId); } else{ //根据可用信息分配更有用的ID wac.setId (getServletContext()); wac.setServletConfig(getServletConfig()); wac.setNamespace(getNamespace ); applyInitializers(wac); //初始化springMVC各种的相关配置,各种注入的Controller,配置文件等 wac.refresh

    91540发布于 2019-02-21
  • 来自专栏国产程序员

    SpringMVC之细说DispatcherServlet

    //这里,ioc容器已经创建初始化完成,执行onRefresh(wac)进一步初始化MVC其他模块,后面说明 onRefresh(wac); } if (getEnvironment()); wac.setParent(parent); wac.setConfigLocation(getContextConfigLocation (ConfigurableWebApplicationContext wac) { if (ObjectUtils.identityToString(wac).equals(wac.getId ()); wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener() ); applyInitializers(wac); //嗲用容器的refresh()方法,完成日期初始化 wac.refresh();

    3.7K30发布于 2019-07-02
  • 来自专栏Tom弹架构

    Spring核心原理之IoC容器初体验(2)

    == null) { wac = findWebApplicationContext(); } //给上一步创建好的IoC容器赋值 if (wac == null) { wac) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { if (this.contextId ! (getServletContext()); wac.setServletConfig(getServletConfig()); wac.setNamespace(getNamespace( )); wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener())); ); applyInitializers(wac); wac.refresh(); } 从上面的代码可以看出,在configAndRefreshWebApplicationContext(

    35930编辑于 2021-12-27
  • 来自专栏Tom弹架构

    Spring核心之IoC容器初体验

    == null) { wac = findWebApplicationContext(); } //给上一步创建好的IoC容器赋值 if (wac == null) { wac) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { if (this.contextId ! (getServletContext()); wac.setServletConfig(getServletConfig()); wac.setNamespace(getNamespace( )); wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener())); ); applyInitializers(wac); wac.refresh(); } 从上面的代码可以看出,在configAndRefreshWebApplicationContext()

    43440编辑于 2022-04-25
  • 来自专栏用户6590312的专栏

    Spring MVC源码解析

    (wac); return wac; } protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application (getServletContext()); wac.setServletConfig(getServletConfig()); wac.setNamespace(getNamespace (wac, new ContextRefreshListener())); // The wac environment's #initPropertySources will be ); applyInitializers(wac); wac.refresh(); } 将WebApplicationContext设置到ServletContext

    48510发布于 2021-01-12
  • 来自专栏coolblog.xyz技术专栏

    Spring MVC 原理探秘 - 容器的创建过程

    (getEnvironment()); wac.setParent(parent); wac.setConfigLocation(getContextConfigLocation()); // 配置并刷新容器 configureAndRefreshWebApplicationContext(wac); return wac; } protected void (wac).equals(wac.getId())) { // 设置容器 id if (this.contextId ! ()); wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener())); postProcessWebApplicationContext(wac); applyInitializers(wac); // 刷新容器 wac.refresh(); } 以上就是创建

    89430发布于 2018-07-05
  • 来自专栏对线JAVA面试

    SpringMvc启动源码解析

    cwac = (ConfigurableWebApplicationContext) wac; if (! has performed any initialization such as setting the context id //如果当前Servlet不存在一个子IoC容器则去查找一下 wac = findWebApplicationContext(); } if (wac == null) { // No context instance is defined for (getEnvironment()); wac.setParent(parent); wac.setConfigLocation(getContextConfigLocation()); configureAndRefreshWebApplicationContext(wac); return wac; }   该方法用于创建一个子IoC容器并将根IoC容器做为其父容器,接着进行配置和刷新操作用于构造相关的

    53310编辑于 2022-10-08
  • 来自专栏springboot

    SpringMVC源码解析

    = null) { //上下文实例在构造时被注入->使用它 wac = this.webApplicationContext; if (wac instanceof ConfigurableWebApplicationContext = findWebApplicationContext(); } if (wac == null) { //创建WebApplicationContext wac = createWebApplicationContext (wac); return wac; } 配置刷新容器 protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { if (this.contextId ! ); //主要是为了在调用refresh方法之前做一些准备工作 applyInitializers(wac); //主动调用refresh方法,触发上面刚添加的监听器 wac.refresh()

    27000编辑于 2025-01-20
  • 来自专栏BAT的乌托邦

    详解Spring Framework提供的扩展点:ApplicationContextInitializer应用上下文初始化器,以及它在SpringBoot中的应用【享学Spring】

    ... } protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac customizeContext(sc, wac); wac.refresh(); ... } // 由此可见所有的ApplicationContextInitializer的执行,都发生在 wac.refresh();之前 protected void customizeContext(ServletContext sc, ConfigurableWebApplicationContext ConfigurableApplicationContext> initializer : this.contextInitializers) { initializer.initialize(wac postProcessWebApplicationContext(wac); applyInitializers(wac); wac.refresh(); } protected void

    1.6K20发布于 2019-09-03
  • 来自专栏java学习java

    SpringMVC执行流程

    ) wac; if (! the parent cwac.setParent(rootContext); } configureAndRefreshWebApplicationContext(cwac); } } } if (wac -> create a local one // 创建WebApplicationContext wac = createWebApplicationContext(rootContext); } if = null) { wac.setConfigLocation(configLocation); } configureAndRefreshWebApplicationContext(wac); return wac; } ③DispatcherServlet初始化策略 FrameworkServlet创建WebApplicationContext后,刷新容器,调用onRefresh(wac),此方法在DispatcherServlet

    56630编辑于 2022-11-13
  • 来自专栏BAT的乌托邦

    【小家Spring】Spring容器(含父子容器)的启动过程源码级别分析(含web.xml启动以及全注解驱动,和ContextLoader源码分析)

    == null) { wac = findWebApplicationContext(); } if (wac == null) { wac = createWebApplicationContext (ConfigurableWebApplicationContext wac) { if (ObjectUtils.identityToString(wac).equals(wac.getId()) (getServletContext()); wac.setServletConfig(getServletConfig()); wac.setNamespace(getNamespace()) (wac, new ContextRefreshListener())); // 同之前~ ConfigurableEnvironment env = wac.getEnvironment() 备注:用到了这个常量ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM applyInitializers(wac); wac.refresh();

    1.9K30发布于 2019-09-03
  • 来自专栏后端沉思录

    SpringMVC启动加载、请求分析

    : this.webApplicationContext = initWebApplicationContext(); initFrameworkServlet(); 跟进第一段代码,由于第一次启动,wac (getEnvironment()); wac.setParent(parent); wac.setConfigLocation(getContextConfigLocation()); configureAndRefreshWebApplicationContext ()); wac.setServletConfig(getServletConfig()); wac.setNamespace(getNamespace()); wac.addApplicationListener (new SourceFilteringListener(wac, new ContextRefreshListener())); // The wac environment's #initPropertySources ); applyInitializers(wac); wac.refresh(); 最后一句 wac.refresh()代码,跟进去发现调用的是 org.springframework.context.support.AbstractApplicationContext

    57330发布于 2018-10-29
  • 来自专栏爪哇缪斯

    (八)Spring源码解析:Spring MVC

    == null) wac = findWebApplicationContext(); /** 步骤3:如果wac还是找不到,则创建一个wac */ if (wac == null ) { /** 步骤1:准备工作——初始化wac */ if (ObjectUtils.identityToString(wac).equals(wac.getId())) { ()); wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener())); ); // 空方法,留给子类去覆盖实现想· applyInitializers(wac); /** 步骤2:调用wac的refresh()方法进行IOC初始化 */ wac.refresh ; return wac; } 1.2.3> 如果wac还是找不到,那就创建一个wac 如果通过上面的努力,我们依然没有获得Web应用上下文,那我们就只好通过createWebApplicationContext

    53350编辑于 2023-09-06
  • 来自专栏JavaQ

    深入理解Spring系列之七:web应用自动装配Spring配置

    sc) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { String idParam = null) { wac.setId(idParam); }else { wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX = null) { wac.setConfigLocation(configLocationParam); } ConfigurableEnvironment ) env).initPropertySources(sc, null); } customizeContext(sc, wac); wac.refresh 关注configureAndRefreshWebApplicationContext方法的最后一行代码wac.refresh(),是不是有点眼熟,继续跟踪代码,refresh方法的具体代码如下。

    85450发布于 2018-04-04
  • 来自专栏愷龍的Blog

    SpringMVC:SpringMVC执行流程

    WebApplicationContextUtils.getWebApplicationContext(getServletContext()); WebApplicationContext wac cwac =(ConfigurableWebApplicationContext) wac; if (! the // user has performed any initialization such as setting the context id wac = findWebApplicationContext(); } if (wac == null) { // No context instance is defined (wac); return wac; } ③DispatcherServlet初始化策略 FrameworkServlet创建WebApplicationContext后,刷新容器,调用onRefresh

    85430编辑于 2023-02-27
  • 来自专栏Java研发军团

    Spring中很重要的ContextLoderListener类,你理解了吗?

    ConfigurableWebApplicationContext.class.getName() + "]"); } ConfigurableWebApplicationContext wac String contextPath = (String) ServletContext.class.getMethod("getContextPath").invoke(sc); wac.setId IllegalStateException("Failed to invoke Servlet 2.5 getContextPath method", ex); } } wac.setParent (parent); wac.setServletContext(sc); wac.setConfigLocation(sc.getInitParameter(CONFIG_LOCATION_PARAM )); customizeContext(sc, wac); wac.refresh(); return wac; } 关闭上下文代码 //关闭指定Servlet上下文中的

    1.1K40发布于 2019-08-13
  • 来自专栏软件开发-青出于蓝

    SpringFramework之DelegatingFilterProxy简析

    WebApplicationContext wac = findWebApplicationContext(); if (wac ! = null) { this.delegate = initDelegate(wac); } } } } @Override public void doFilter = findWebApplicationContext(); if (wac == null) { throw new IllegalStateException("No WebApplicationContext ; } delegateToUse = initDelegate(wac); } this.delegate = delegateToUse; } } ; } delegateToUse = initDelegate(wac); } this.delegate = delegateToUse; } }

    1.6K40发布于 2019-04-15
  • 来自专栏玩转JavaEE

    SpringMVC 初始化流程分析

    == null) { wac = findWebApplicationContext(); } if (wac == null) { wac = createWebApplicationContext 这三套组合拳下来,wac 肯定是有值了。 最后将 wac 保存到到 ServletContext 中。 wac) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application context id ()); wac.setServletConfig(getServletConfig()); wac.setNamespace(getNamespace()); wac.addApplicationListener

    53410发布于 2021-03-16
领券