Spring Boot Web容器类型推断

static WebApplicationType deduceFromClasspath() {
    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;
}
  1. Spring boot总共有三种web应用类型
    • reactive

The application should run as a reactive web application and should start an embedded reactive web server.
* servlet

The application should run as a servlet-based web application and should start an embedded servlet web server.
* none

The application should not run as a web application and should not start an embedded web server.

  1. Spring boot依据Class path来推断web应用类型
    • reactive
      路径包含org.springframework.web.reactive.DispatcherHandler,并且不包含org.springframework.web.servlet.DispatcherServletorg.glassfish.jersey.servlet.ServletContainer
    • none
      不是reactive,并且路径中没有javax.servlet.Servletorg.springframework.web.context.ConfigurableWebApplicationContext
    • servlet
      剩余的部分都是servlet

你可能感兴趣的:(Spring Boot Web容器类型推断)