崛起於Springboot2.0.X之切換使用Servlet容器Jetty、Tomcat、Undertow(38)

一、配置

1.1 pom配置

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

若是使用Jetty容器,那麼添加web

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

若是使用Undertow容器,那麼添加spring

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
</dependency

二、切換Servlet容器

2.1 版本2.0如下,1.X的版本切換Jetty、Undertow

在啓動類,添加tomcat

@Bean
public EmbeddedServletContainerFactory servletContainer() {
    JettyEmbeddedServletContainerFactory factory =
            new JettyEmbeddedServletContainerFactory();
    return factory;
}

若是你想換成Undertow,那麼把上面中Jetty五個字母替換成Undertowspring-boot

2.2 版本2.0以上,2.X版本切換Jetty、Undertow

在啓動類添加spa

@Bean public ServletWebServerFactory servletContainer() {
    JettyServletWebServerFactory tomcat = new JettyServletWebServerFactory();
    return tomcat;
}

若是你想換成Undertow,那麼把上面中Jetty五個字母替換成Undertowservlet

相關文章
相關標籤/搜索