美文网首页
Spring Boot WebApplicationType

Spring Boot WebApplicationType

作者: 莫夏_b560 | 来源:发表于2023-06-12 16:43 被阅读0次

一 、WebApplicationType

The WebApplicationType is an enumeration of possible types of web applications. There are three possible values:

(1)NONE
the application should not run as a web application and should not start an embedded web server.

(2)REACTIVE
the application should run as a reactive web application and should start an embedded reactive web server.

(3)SERVLET
the application should run as a servlet-based web application and should start an embedded servlet web server.

二、how to set the WebApplicationType

public enum WebApplicationType {
    NONE,
    SERVLET,
    REACTIVE;

    private static final String[] SERVLET_INDICATOR_CLASSES = new String[]{"javax.servlet.Servlet", "org.springframework.web.context.ConfigurableWebApplicationContext"};
    private static final String WEBMVC_INDICATOR_CLASS = "org.springframework.web.servlet.DispatcherServlet";
    private static final String WEBFLUX_INDICATOR_CLASS = "org.springframework.web.reactive.DispatcherHandler";
    private static final String JERSEY_INDICATOR_CLASS = "org.glassfish.jersey.servlet.ServletContainer";

    private WebApplicationType() {
    }

    static WebApplicationType deduceFromClasspath() {
        if (ClassUtils.isPresent("org.springframework.web.reactive.DispatcherHandler", (ClassLoader)null) && !ClassUtils.isPresent("org.springframework.web.servlet.DispatcherServlet", (ClassLoader)null) && !ClassUtils.isPresent("org.glassfish.jersey.servlet.ServletContainer", (ClassLoader)null)) {
            return REACTIVE;
        } else {
            String[] var0 = SERVLET_INDICATOR_CLASSES;
            int var1 = var0.length;

            for(int var2 = 0; var2 < var1; ++var2) {
                String className = var0[var2];
                if (!ClassUtils.isPresent(className, (ClassLoader)null)) {
                    return NONE;
                }
            }

            return SERVLET;
        }
    }
}

三、Spring Boot example

@SpringBootApplication
public class Application {

    public static void main(String[] args) {

        new SpringApplicationBuilder(Application.class)
                .web(WebApplicationType.SERVLET)
                .run(args);
    }
}

相关文章

网友评论

      本文标题:Spring Boot WebApplicationType

      本文链接:https://www.haomeiwen.com/subject/awdqydtx.html