Spring container type inference

springboot defined WebApplicationType enumeration specifies the type of web application.

. 1  public  enum WebApplicationType {
 2      NONE, // non WEB application, does not start the embedded WEB container 
. 3      SERVLET, // support Servlet WEB application, starts an embedded servlet web container 
. 4      REACTIVE; // support of reactive WEB application, starts embedded reactive web container
 5      // ...... omitted 
6 }

WebApplicationType will be inferred in the constructor SpringApplication, decide which type to use.

1 this.webApplicationType = WebApplicationType.deduceFromClasspath();

Core code in deduceFromClassPath () method

 1 static WebApplicationType deduceFromClasspath() {
 2     if (ClassUtils.isPresent(WEBFLUX_INDICATOR_CLASS, null) && !ClassUtils.isPresent(WEBMVC_INDICATOR_CLASS, null)
 3             && !ClassUtils.isPresent(JERSEY_INDICATOR_CLASS, null)) {
 4         return WebApplicationType.REACTIVE;
 5     }
 6     for (String className : SERVLET_INDICATOR_CLASSES) {
 7         if (!ClassUtils.isPresent(className, null)) {
 8             return WebApplicationType.NONE;
 9         }
10     }
11     return WebApplicationType.SERVLET;
12 }

Second line code, determining a first specified DispatcherHandler webflux class exists. If there is, and there is no DispatcherServlet and ServletContainer class, then it is concluded Reactive type.

If you do not meet the above criteria, then the default is SERVLET type. At this time continues to determine the class type associated with the presence or absence Servlet, it is determined in the related class traverse line 6:

1) determining whether there is a Servlet interface

2) determining whether there is an interface ConfigurableWebApplicationContext

If both of which have a non-existent, it means that Servlet application is not directly identified as the type NONE, non WEB applications.

Otherwise SERVLET type.

WebApplicationType inferred type, according to the classpath iconic interface or class as determined. Judging process to determine whether REACTIVE type, and then determine whether SERVLET type, if neither, then that is non WEB applications.

 

Guess you like

Origin www.cnblogs.com/lay2017/p/11408907.html