SpringBoot中MVC的调用流程
2021-06-30 13:11:15 1 举报
mvc
作者其他创作
大纲/内容
当初始化到RequestMappinghandlerMapping时
HandlerMethod handlerMethod = lookupHandlerMethod
refreshContext
DEFAULT_CONTEXT_CLASS = \"org.springframework.context.annotation.AnnotationConfigApplicationContext\";
HandlerMethod handler =super.getHandlerInternal
initHandlerMethods
HandlerExecutionChain mappedHandler=getHandler(processedRequest)
BootstrapApplicationListener.AncestorInitializer在此时,将父容器注入到子容器中
获取拦截器链,以责任链的方式调用拦截器的preHandle方法
createWithResolvedBean把这个handler的bean(Controller)创建了
DEFAULT_SERVLET_WEB_CONTEXT_CLASS = \"org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext\"
invocableMethod.setHandlerMethodReturnValueHandlers(this.returnValueHandlers);
根据 isHandler(beanType)
BootstrapApplicationListener.onApplicationEvent
detectHandlerMethods(beanName)
浏览器发出请求
applyInitializers
SpringApplicationBuilder.web(WebApplicationType.NONE)
设置WebDataBinderFactory binderFactory
DispatcherServlet
finishBeanFactoryInitialization
matches.sort(comparator); Match bestMatch = matches.get(0);找到最合适的
注册你启动时传入的那个Application类的Bean定义
SpringApplication.run
获取WebAsyncManager
SpringApplication.createApplicationContext
invocableMethod.setParameterNameDiscoverer(this.parameterNameDiscoverer);
根据@RequestMapping获取该类的method和path的包装的映射表
根据CorsUtils.isCorsRequest(request)进行Cors处理
开始调父类AbstractHandlerMethodMapping
afterPropertiesSet
处理完注册后,MappingRegistry根据@CrossOrigin处理跨域initCorsConfiguration
以持有实例化的Controller的HandlerMethod作为handler进行创建HandlerExecutionChain
设置参数解析器HandlerMethodArgumentResolverComposite
注册一个ApplicationConversionService
从三种适配器(RequestMappingHandlerAdapter,HttpRequestHandlerAdapter,SimpleControllerHandlerAdapter)中选择一种适配器,注解@Controller形式默认是RequestMappingHandlerAdapter
addAncestorInitializer
SpringApplication.createApplicationContext();
prepareContext
设置返回值解析器HandlerMethodReturnValueHandlerComposite
postProcessApplicationContext
doDispatch
对所有的Bean进行映射处理
把初始化好的上下文放入始祖初始监听器里,用于将父容器注入到子容器
Spring加载bean的那一套,暂时忽略
创建父容器
refreshContext()
找到所有匹配的RequestMappingInfo
SimpleApplicationEventMulticaste.invokeListener
handlerMethodsInitialized(getHandlerMethods())
load
invocableMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
prepareEnvironment
HandlerExecutionChain handler = RequestMappingHandlerMappin.getHandler(request)
HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());
ForEach:processCandidateBean
创建子容器
把上一步得到的映射表,遍历包装注册到mappingRegistry里,供使用时返回chain
直到
0 条评论
下一页