- 使用@WebServlet(urlPatterns = "/my")时直接响应,没有经过Spring的拦截器
| DispatchServlet 如何注册进来 |
| 容器中自动配置了 DispatcherServlet 属性绑定到 WebMvcProperties;对应的配置文件配置项是 spring.mvc。 |
| 通过 ServletRegistrationBean<DispatcherServlet> 把 DispatcherServlet 配置进来。 |
| 默认映射的是 / 路径 |
| |
| Tomcat-Servlet; |
| 多个Servlet都能处理到同一层路径,精确优选原则 |
| A: /my/ |
| B: /my/1 |

| SpringBoot应用启动发现当前是Web应用。web场景包-导入tomcat |
| web应用会创建一个web版的ioc容器 ServletWebServerApplicationContext |
| ServletWebServerApplicationContext 启动的时候寻找 ServletWebServerFactory(Servlet 的web服务器工厂---> Servlet 的web服务器) |
| SpringBoot底层默认有很多的WebServer工厂;TomcatServletWebServerFactory, JettyServletWebServerFactory, or UndertowServletWebServerFactory |
| 底层直接会有一个自动配置类。ServletWebServerFactoryAutoConfiguration |
| ServletWebServerFactoryAutoConfiguration导入了ServletWebServerFactoryConfiguration(配置类) |
| ServletWebServerFactoryConfiguration 配置类 根据动态判断系统中到底导入了那个Web服务器的包。(默认是web-starter导入tomcat包),容器中就有 TomcatServletWebServerFactory |
| TomcatServletWebServerFactory 创建出Tomcat服务器并启动;TomcatWebServer 的构造器拥有初始化方法initialize---this.tomcat.start(); |
| 内嵌服务器,就是手动把启动服务器的代码调用(tomcat核心jar包存在) |
| |
| Tomcat, Jetty, or Undertow |
| ServletWebServerApplicationContext 容器启动寻找ServletWebServerFactory 并引导创建服务器 |
| <dependency> |
| <groupId>org.springframework.boot</groupId> |
| <artifactId>spring-boot-starter-web</artifactId> |
| <exclusions> |
| <exclusion> |
| <groupId>org.springframework.boot</groupId> |
| <artifactId>spring-boot-starter-tomcat</artifactId> |
| </exclusion> |
| </exclusions> |
| </dependency> |
| 修改配置文件 server.xxx |
| |
| 实现 WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> |
| 把配置文件的值和ServletWebServerFactory 进行绑定 |
| |
| xxxxxCustomizer:定制化器,可以改变xxxx的默认规则 |
| @Component |
| public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> { |
| |
| @Override |
| public void customize(ConfigurableServletWebServerFactory server) { |
| server.setPort(9000); |
| } |
| |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?