SpringBoot复习(39)Servlet容器的自动配置原理

Servlet容器自动配置类为ServletWebServerFactoryAutoConfiguration
SpringBoot复习(39)Servlet容器的自动配置原理_第1张图片
可以看到通过@Import注解导入了三个配置类:
SpringBoot复习(39)Servlet容器的自动配置原理_第2张图片
SpringBoot复习(39)Servlet容器的自动配置原理_第3张图片
SpringBoot复习(39)Servlet容器的自动配置原理_第4张图片
通过这个这三个配置类可以看出,它们都使用了@ConditionalOnClass注解,当类路径存在tomcat相关的类时,会配置一个TomcatServletWebServerFactory类型的bean, 当类路径存在jetty相关的类时,会配置一个JettyServletWebServerFactory 类型的bean, 当类路径存在undertow相关的类时,会配置一个UndertowServletWebServerFactory类型的bean。
这样就完成了根据pom.xml中引入了不同的依赖来决定使用哪种Servlet容器。

        
            org.springframework.boot
            spring-boot-starter-tomcat
        
        
            org.springframework.boot
            spring-boot-starter-undertow
        
        
            org.springframework.boot
            spring-boot-starter-jetty
        

你可能感兴趣的:(SpringBoot,spring,boot,servlet,后端)