首页 > 编程语言 > 详细

Spring MVC之FrameworkServlet源码分析

时间:2018-05-06 18:18:56      阅读:236      评论:0      收藏:0      [点我收藏+]

FrameworkServlet是HttpServletBean的子类,实现了HttpServletBean 的 initServletBean 方法。

通过initServletBean()进行WebApplicationContext初始化,其源码为:

 

 1     /**
 2      * Overridden method of {@link HttpServletBean}, invoked after any bean properties
 3      * have been set. Creates this servlet‘s WebApplicationContext.
 4      */
 5     @Override
 6     protected final void initServletBean() throws ServletException {
 7         getServletContext().log("Initializing Spring FrameworkServlet ‘" + getServletName() + "‘");
 8         if (this.logger.isInfoEnabled()) {
 9             this.logger.info("FrameworkServlet ‘" + getServletName() + "‘: initialization started");
10         }
11         long startTime = System.currentTimeMillis();
12 
13         try {
14             this.webApplicationContext = initWebApplicationContext();
15             initFrameworkServlet();
16         }
17         catch (ServletException ex) {
18             this.logger.error("Context initialization failed", ex);
19             throw ex;
20         }
21         catch (RuntimeException ex) {
22             this.logger.error("Context initialization failed", ex);
23             throw ex;
24         }
25 
26         if (this.logger.isInfoEnabled()) {
27             long elapsedTime = System.currentTimeMillis() - startTime;
28             this.logger.info("FrameworkServlet ‘" + getServletName() + "‘: initialization completed in " +
29                     elapsedTime + " ms");
30         }
31     }

其主要的功能就是调用initWebApplicationContext方法初始化一个WebApplicationContext。

以下是initWebApplicationContext的源码:

 

Spring MVC之FrameworkServlet源码分析

原文:https://www.cnblogs.com/smile_to_warm/p/8998987.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!