Spring mvc3.2 startup Analysis
1,GenericServlet public void init(ServletConfig config) throws ServletException {this.config = config;this.init(); }2,HttpServletBeanpublic final void init() throws ServletException {if (logger.isDebugEnabled()) {logger.debug("Initializing servlet '" + getServletName() + "'");}// Set bean properties from init parameters.try {PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties);BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext());bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));initBeanWrapper(bw);bw.setPropertyValues(pvs, true);}catch (BeansException ex) {logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex);throw ex;}// Let subclasses do whatever initialization they like.initServletBean();
If (logger. isDebugEnabled () {logger. debug ("Servlet" + getServletName () + "'configured succeeded");} 3, create WebApplicationContext @ custom final void initServletBean () throws ServletException {getServletContext () According to xmlWebApplicationContext (). log ("Initializing Spring FrameworkServlet '" + getServletName () + "'"); if (this. logger. isInfoEnabled () {this.logger.info ("FrameworkServlet" + getSe RvletName () + "': initialization started");} long startTime = System. currentTimeMillis (); try {this. webApplicationContext = initWebApplicationContext (); initFrameworkServlet ();} catch (ServletException ex) {this. logger. error ("Context initialization failed", ex); throw ex;} catch (RuntimeException ex) {this. logger. error ("Context initialization failed", ex); throw ex;} if (this. logger. isInfoEnabled () {long ElapsedTime = System. currentTimeMillis ()-startTime; this.logger.info ("FrameworkServlet" + getServletName () + "': initialization completed in" + elapsedTime + "ms") ;}} 4, DispatcherServlet (FrameworkServlet) protected void initStrategies (ApplicationContext context) {initMultipartResolver (context); initLocaleResolver (context); initThemeResolver (context); initHandlerMappings (context); initHandlerAdapter S (context); terminate (context); initViewResolvers (context); initFlashMapManager (context) ;}5, FrameworkServletprotected void Merge (ConfigurableWebApplicationContext wac) {if (ObjectUtils. identityToString (wac ). equals (wac. getId () {// The application context id is still set to its original default value //-> Assign a more useful id based on available informationif (this. contextId! = Null) {wac. setId (this. contextId);} else {// Generate default id... servletContext SC = getServletContext (); if (SC. getMajorVersion () = 2 & SC. getMinorVersion () <5) {// Servlet <= 2.4: resort to name specified in web. xml, if any. string servletContextName = SC. getServletContextName (); if (servletContextName! = Null) {wac. setId (ConfigurableWebApplicationContext. APPLICATION_CONTEXT_ID_PREFIX + servletContextName + ". "+ getServletName ();} else {wac. setId (ConfigurableWebApplicationContext. APPLICATION_CONTEXT_ID_PREFIX + getServletName () ;}} else {// Servlet 2.5's getContextPath available! Wac. setId (ConfigurableWebApplicationContext. APPLICATION_CONTEXT_ID_PREFIX + ObjectUtils. getDisplayString (SC. getContextPath () + "/" + getServletName () ;}} wac. setServletContext (getServletContext (); wac. setServletConfig (getServletConfig (); wac. setNamespace (getNamespace (); wac. addApplicationListener (new SourceFilteringListener (wac, new ContextRefreshListener (); // the wac environment's # initPropertySources will be called any in case when // the context is refreshed; do it eagerly here to ensure servlet property sources // are in place for use in any post-processing or initialization that occurs // below prior to # refreshConfigurableEnvironment env = wac. getEnvironment (); if (env instanceof ConfigurableWebEnvironment) {(ConfigurableWebEnvironment) env ). initPropertySources (getServletContext (), getServletConfig ();} postProcessWebApplicationContext (wac); applyInitializers (wac); wac. refresh ();} 6, exit Method