SpringMVC 源码流程
2022-04-02 11:51:49 0 举报
SpringMVC源码流程分析
作者其他创作
大纲/内容
initWebApplicationContext(ServletContext servletContext)
WebApplicationContextspring-mvc2.xmlHelloV2Controller
protected void initServletBean() throws ServletException { }这是一个-空方法在子类实现
创建DispatcherServlet自己的spring容器
class ContextLoader
DispatcherServlet
this.initWebApplicationContext(event.getServletContext());
class FrameworkServlet
DispatcherServlet创建流程
将root容器,存入servletContext中,以被创建DispatcherServlet自己的spring容器时设置父子容器关联时使用
createWebApplicationContext(@Nullable WebApplicationContext parent)
class DispatcherServlet
protected WebApplicationContext createWebApplicationContext(ServletContext sc) { Class<?> contextClass = this.determineContextClass(sc); //取得子容器的类型 if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) { throw new ApplicationContextException(\"Custom context class [\" + contextClass.getName() + \"] is not of type [\" + ConfigurableWebApplicationContext.class.getName() + \"]\"); } else { return (ConfigurableWebApplicationContext)BeanUtils.instantiateClass(contextClass); } }
WebApplicationContextspring-mvc.xmlHelloController
class HttpServletBean
创建 root 容器
if (wac == null) { wac = this.createWebApplicationContext(rootContext); }
this.webApplicationContext = this.initWebApplicationContext();
读取web.xml中的contextConfigLocation 装入 <context:component-scan base-package=\"com.gok\
classFrameworkServlet
父容器
this.initServletBean();
子容器
ContextLoaderListenerroot容器创建流程
class ContextLoaderListener
HellerServiceImplHelloServiceImpl
返回根容器 return this.context;
contextInitialized(ServletContextEvent event)
if (this.context == null) { this.context = this.createWebApplicationContext(servletContext); }
initWebApplicationContext()
init
收藏
0 条评论
下一页