當前位置:
首頁 > 知識 > Springboot2.X之切換使用Servlet容器Jetty、Tomcat、Undertow

Springboot2.X之切換使用Servlet容器Jetty、Tomcat、Undertow

1、配置

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容器,那麼添加

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

如果使用Undertow容器,那麼添加

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

2、切換Servlet容器

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

在啟動類,添加

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

如果你想換成Undertow,那麼把上面中Jetty五個字母替換成Undertow

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

在啟動類添加

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

如果你想換成Undertow,那麼把上面中Jetty五個字母替換成Undertow

Springboot2.X之切換使用Servlet容器Jetty、Tomcat、Undertow

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 程序員小新人學習 的精彩文章:

使用KETTLE從mysql同步增量數據到oracle
TypeScript基礎之高級類型的可辨識聯合(Discriminated Unions)

TAG:程序員小新人學習 |