SpringMVC
2020-03-31 15:37:29 1 举报
Spring MVC时序图
作者其他创作
大纲/内容
ModelAndView = invokeHandlerMethod()
new ContextLoaderListener()
如果DispatcherServlet没有初始化ApplicationContext,findWebApplicationContext()
initializer.onStartup(servletContext)
AbstractContextLoaderInitializer
创建AnnotationConfigWebApplicationContext
getHandler()
initThemeResolver()初始化模板处理
registerBeanDefinitionParser()
initControllerAdviceCache()简单一点添加ControllerAdvice Bean
ContextLoader
初始化Servlet,调用init()方法,只会被调用一次,HttpServlet <- HttpServletBean <- FrameworkServlet <- DispatcherServlet
registerServletFilter
initWebApplicationContext
loop handlerMappingsgetHandler(request)
detectMappedInterceptors(this.adaptedInterceptors)
initApplicationContext()
configureAndRefreshWebApplicationContext
RequestMappingHandlerMapping
createRootApplicationContext()
onStart()
如果find也找不到,则createWebApplicationContext(),setParent(rootContext)
isHandler()检查是否有Controller和RequestMapping注解
loop adaptedInterceptorshandlerExecutionChain.addInteceptor()
SPI,tomcat启动时加载应用的时候,会运行ServletContainerInitializer.onStartup()方法Spring-web里面有SpringServletContainerInitializer,主要是替换了web.xml的功能
AbstractHandlerMapping
rootContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext())
getHandlerAdapter()return RequestMappingHandlerAdapter
doService
initViewResolvers()初始化视图转换器
MvcNamespaceHandler
AnnotationDrivenBeanDefinitionParser
调用阶段
这里会拿到InterceptorsBeanDefinitionParser注册的MappedInteceptor,并进行初始化inteceptor的bean
如果preHandler过了,然后调用报错,在Catch(Exception)里面还会调用triggerAfterCompletion
registerDispatcherServlet
afterPropertiesSet
getHandlerInternal(request)
AbstractHandlerMethodMapping
initLocaleResolver()初始化模本地语言环境
MvcNamespaceHandler里面生成HandlerMapping的实例,这边initHandlerMapping则将这些bean放到handlerMappings属性上
RequestMappingHandlerAdapter
ApplicationContextInitializer.initialize()
获取webApplicationContextDispatcherServlet已经创建了子ApplicationContext则直接setParent(rootContext)
new
onRefresh()
processCandidateBean(beanName)
DispatcherServlet
主要从mappingRegistry里面找到lookupPath对应的handlerMethod并返回
processDispatchResult()
if context== nullcreateWebApplicationContext
checkMultipart
ReflectionUtils.accessibleConstructor(waiClass).newInstance()
lookupPath = getUrlPathHelper().getLookupPathForRequest(request)
afterPropertiesSet()
handlerExecutionChain.applyPreHandle()
initHandlerMappings()
SpringServletContainerInitializer
HandlerAdapter.handle()调用真正的方法
RequestMappingHandlerAdapter()
handleInternal()
getCandidateBeanNames()获取beanName(Controller)
initFlashMapManager()
handlerExecutionChain.triggerAfterCompletion
detectHandlerMethods(beanName)
initHandlerExceptionResolvers()
ContextLoadListener初始化RootApplicationContext,通过SPI之后,applicationContext已经创建了,就不需要再创建。
registerHandlerMethod()
handlerExecutionChain.applyPostHandle()
extends
servletContext.addServlet
initRequestToViewNameTranslator()初始化视图预处理器
createDispatcherServlet
init()
initServletBean()
servletContext.addListener(listener)
addMapping
registerContextLoaderListener
initMultipartResolver()d文件上传组件
handle()
initHandlerMethods()
RequestMappingHandlerMapping()
HttpServletBean
applyDefaultViewName()
contextInitialized
createServletApplicationContext()
initHandlerAdapters()
AbstractDispatcherServletInitializer
detectHandlerMethods()
doDispatch
BeanWrapper.setPropertyValues()根据web.xml配置给DispatcherServlet属性赋值
initStrategies()
ContextLoaderListener
拿到WebApplicationInitializer的实现类,进行初始化之后调用实现类的onStart()方法
FrameworkServlet
wac.refresh()初始化Bean
customizeContext
0 条评论
下一页