【问题标题】:When does onRefresh method of DispatcherServlet gets called?什么时候调用 DispatcherServlet 的 onRefresh 方法?
【发布时间】:2018-08-04 14:50:20
【问题描述】:

什么时候调用 DispatcherServlet 的 onRefresh 方法?

【问题讨论】:

标签: spring-mvc servlets


【解决方案1】:
DispatcherServlet extends FrameworkServlet
FrameworkServlet extends HttpServletBean
HttpServletBean extends HttpServlet
  • HttpServletBean 覆盖了 GenericServlet 的 init() 方法,它调用了被 FrameworkServlet 覆盖的 initServletBean() 方法

  • 在FrameworkServlet的initServletBean()方法中调用了initWebApplicationContext()方法

  • 在该方法中,它检查 webApplicationContext 是否是 ConfigurableWebApplicationContext 的实例
  • 如果是,则调用configureAndRefreshWebApplicationContext()方法
  • 在 webApplicationContext 上调用 refresh 方法
  • 查看 AbstractApplicationContext 中 refresh() 方法的实现,最后它调用了 finishRefresh() 方法
  • 在该方法中它发布 ContextRefreshedEvent
  • 在 FrameworkServlet 中有一个私有类 ContextRefreshListener 实现了 ApplicationListener
  • 此类的 onApplicationEvent() 方法调用 FrameworkServlet 的 onApplicationEvent() 方法
  • 在该方法中,它调用了由 DispatcherServlet 覆盖的 onRefresh 方法

【讨论】:

    猜你喜欢
    • 2011-07-21
    • 1970-01-01
    • 2015-07-13
    • 2012-11-30
    • 2012-05-16
    • 2018-01-01
    • 2016-04-13
    相关资源
    最近更新 更多