gpt4 book ai didi

SpringMVC-运行原理和源码解析

转载 作者:知者 更新时间:2024-03-13 04:42:57 24 4
gpt4 key购买 nike

基于SpringBoot版本如下:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

运行原理

关键源码解析

SpringBoot的自动化配置关于SpringMVC的配置类是中是WebMvcAutoConfiguration,详情参见spring.factories
处理器和适配器的bean是在WebMvcAutoConfiguration的内部类 EnableWebMvcConfiguration里配置的。

1、获取应用上下文信息

使用ApplicationContextAware#setApplicationContext的方法初始化应用上下文

2、初始化URL映射处理器

使用InitializingBean#afterPropertiesSet初始化获取所有url和处理器的映射

3、DispatcherServlet初始化

当接收到第一个请求时进行初始化,HttpServlet#init--> DispatcherServlet#onRefresh
然后处理请求,执行doDispatch方法

initHandlerMappings

initHandlerAdapters

4、执行doDispatch方法

通过URL获取处理器,再找到处理器适配器,用适配器执行

getHandler

getHandlerAdapter

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com