English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

SpringBoot Starter Web

spring-boot-starter-Web has two important features:

Compatible with web development Automatic configuration

If you want to develop a web application, you need to add the following dependencies to the pom.xml file:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>

The Spring web starter uses Spring MVC, REST, and Tomcat as the default embedded server. Single spring-boot-starter-Web dependencies can transitively obtain all dependencies related to Web development. It also reduces the count of build dependencies. spring-boot-starter-The web is transitively dependent on the following contents:

org.springframework.boot: spring-boot-starter org.springframework.boot: spring-boot-starter-tomcat org.springframework.boot: spring-boot-starter-validation com.fasterxml.jackson.core: jackson-databind org.springframework: spring-web org.springframework: spring-webmvc

By default, spring-boot-starter-web includes the following Tomcat server dependencies:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.0.0.RELEASE</version>
<scope>compile</scope>
</dependency>

spring-boot-starter-Spring Boot automatically configures the following for Web development:

scheduler Servlet error pages Web JAR used to manage static dependencies embedded servlet container

Spring Boot embedded Web server

Each Spring Boot application includes an embedded server. The embedded server is embedded as part of the deployable application. The advantages of the embedded server are that we do not need to pre-install the server in the environment. With Spring Boot, the default embedded server is Tomcat . Spring Boot also supports two other embedded servers:

Jetty server Undertow server

using other embedded Web servers

for servlet stackapplication, spring-boot-starter-web by including spring-boot-starter-tomcat to include Tomcat but we can use spring-boot-starter-jetty or spring -boot-starter-undertow .

for reactorapplication, spring-boot-starter-webflux including including spring-boot-starter-reactor-netty to implement Reactor Netty , but we can use spring-boot-starter-tomcat, spring-boot-starter-jetty

Jetty server

Spring Boot also supports the so-called Jetty server. It is an HTTP server and Servlet container with the ability to provide static and dynamic content.

If you want to add the Jetty server to the application, you need to add spring-boot-starter-jetty dependencies.

Remember: . Ensure that you are using the Jetty server when using the application excluded the default Tomcat server spring-boot-starter-web . It avoids conflicts between servers.

<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

we can also use application.properties file to customize the behavior of the Jetty server.

Undertow Server

Spring Boot provides another named Undertow server. It is also an embedded Web server like Jetty. It is written in Java, managed and sponsored by JBoss. The main advantages of the Undertow server are:

supports HTTP/2 HTTP upgrade support Websocket support provides support for Servlet 4.0 support flexible embeddable

Remember: : Ensure that you are using from the application when using the Undertow server spring-boot-starterexcluded the default Tomcat server -web.avoiding conflicts between servers.

<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

we can also use application.properties file to customize the behavior of the Undertow server.

spring-boot-starter-web vs. spring-boot-starter-tomcat

spring-boot-starter-web includes the spring web dependencies, including spring-boot-starter-tomcat. spring-boot-starter-web includes the following contents:

spring-boot-starter jackson spring-core spring-mvc spring-boot-starter-tomcat

spring-boot-starter-tomcat Contains all the content related to the Tomcat server.

core el logging websocket

starter-Tomcat has the following dependencies:

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.5.23</version>
 <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<version>8.5.23</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>8.5.23</version>
<scope>compile</scope>
</dependency>

We can also use spring-mvc Instead of using an embedded Tomcat server. If you want to do this, we need to use  Exclude Tomcat server as shown in the following code.

<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>