Spring mvc3.2 startup Analysis

Source: Internet
Author: User

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

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.