protectedvoidprepareRefresh(){// Switch to active.//指定刷新容器的开始时间this.startupDate =System.currentTimeMillis();//设置容器是开启状态this.closed.set(false);//设置容器是激活状态this.active.set(true);if(logger.isDebugEnabled()){if(logger.isTraceEnabled()){
logger.trace("Refreshing "+this);}else{
logger.debug("Refreshing "+getDisplayName());}}// Initialize any placeholder property sources in the context environment.//加载环境变量 后面可能会有占位符(${}) 需要替换实际的值//主要是加载 StandardServletEnvironment servletContextInitParams,servletConfigInitParams,jndiPropertiesinitPropertySources();// Validate that all properties marked as required are resolvable:// see ConfigurablePropertyResolver#setRequiredProperties//校验环境变量必不可少的属性,如果缺少,则报错getEnvironment().validateRequiredProperties();// Store pre-refresh ApplicationListeners...//这里加这个判断的原因是因为 当是SpringMvc加载启动创建容器时,SpringMvc中会有一些提前创建好的监听器//如果是这样的话,会将SpringMvc及Spring中的监听器都放到applicationListeners中//再当前只是刷新Spring容器会走这个if判断if(this.earlyApplicationListeners ==null){this.earlyApplicationListeners =newLinkedHashSet<>(this.applicationListeners);}else{// Reset local application listeners to pre-refresh state.this.applicationListeners.clear();this.applicationListeners.addAll(this.earlyApplicationListeners);}// Allow for the collection of early ApplicationEvents,// to be published once the multicaster is available...//创建事件集合空容器this.earlyApplicationEvents =newLinkedHashSet<>();}
initPropertySources()方法
protectedvoidinitPropertySources(){// For subclasses: do nothing by default.//提供给子类实现 这里是AbstractRefreshableWebApplicationContenxt}
publicstaticvoidinitServletPropertySources(MutablePropertySources sources,@NullableServletContext servletContext,@NullableServletConfig servletConfig){Assert.notNull(sources,"'propertySources' must not be null");//servletContextInitParams 指的是Servlet上下文中的参数String name =StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME;if(servletContext !=null&& sources.get(name)instanceofStubPropertySource){
sources.replace(name,newServletContextPropertySource(name, servletContext));}//servletConfigInitParams 指的是Servlet的配置项中的参数
name =StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME;if(servletConfig !=null&& sources.get(name)instanceofStubPropertySource){
sources.replace(name,newServletConfigPropertySource(name, servletConfig));}}