SpringBoot启动过程深度解析——WebApplicationType

SpringBoot启动过程深度解析——WebApplicationType


WebApplicationType是Web应用程序类型的枚举,包含以下类型:

  • NONE:应用程序不应作为 Web 应用程序运行,也不应启动嵌入式 Web 服务器
  • SERVLET:应用程序应作为基于 servlet 的 Web 应用程序运行,并应启动嵌入式 servlet Web 服务器
  • REACTIVE:应用程序应作为反应式 Web 应用程序运行,并应启动嵌入式反应式 Web 服务器

WebApplicationType的判断逻辑


public enum WebApplicationType {

    static WebApplicationType deduceFromClasspath() {
      /**
      
        WebApplicationType.REACTIVE:
          需要此类:
            org.springframework.web.reactive.DispatcherHandler
          并且不含这两类:
            org.glassfish.jersey.servlet.ServletContainer
            org.springframework.web.servlet.DispatcherServlet

        WebApplicationType.NONE
          不含以下其中一个类:
            【tomcat包】javax.servlet.Servlet
            【spring-web包】org.springframework.web.context.ConfigurableWebApplicationContext

        WebApplicationType.SERVLET
          需要包含这两个类:
            【tomcat包】javax.servlet.Servlet
            【spring-web包】org.springframework.web.context.ConfigurableWebApplicationContext


      **/
        if (ClassUtils.isPresent(WEBFLUX_INDICATOR_CLASS, null) && !ClassUtils.isPresent(WEBMVC_INDICATOR_CLASS, null)
            && !ClassUtils.isPresent(JERSEY_INDICATOR_CLASS, null)) {
          return WebApplicationType.REACTIVE;
        }
        for (String className : SERVLET_INDICATOR_CLASSES) {
          if (!ClassUtils.isPresent(className, null)) {
            return WebApplicationType.NONE;
          }
        }
        return WebApplicationType.SERVLET;
      }
}

你可能感兴趣的:(java,spring,spring,boot,后端,架构)