SpringBoot如何省去Web.xml?

1、Web.xml 是Spring应用和Servlet联系的中介

Servlet容器启动后,Servlet容器会根据web.xml中的配置初始化Spring容器。

2、Servlet3.0奠定了SpringBoot 零xml配置的基础

在Servlet3.0容器初始化时会调用jar包META-INF/services/javax.servlet.ServletContainerInitializer中指定的类的实现(javax.servlet.ServletContainerInitializer中的实现替代了web.xml的作用,而所谓的在@HandlesTypes注解中指定的感兴趣的类(如WebApplicationInitializer.class),可以理解为具体实现了web.xml的功能,当然也可以有其他的用途)。
Servlet3.0容器(Tomcat)-> SpringServletContainerInitializer.onStartup()->WebApplicationInitializer.onStartup()->createRootApplicationContext(Spring容器)
SpringBoot如何省去Web.xml?_第1张图片
参考: https://www.cnblogs.com/hello-shf/p/10976646.html

你可能感兴趣的:(Spring)