Spring boot embedded web server
Every application in spring boot has an embedded server. The server is embedded as a part of the deployable application. The advantage of the embedded server is that it does not require a pre-installed server. Instead, the embedded web server has a default embedded server called the Tomcat. Other embedded systems supported apart from default are jetty server and undertow server. The spring boot starter includes Tomcat and spring boot starter for application in the servlet stack. We can also use a spring boot starter jetty or spring boot starter undertow.
Jetty server
A Jetty server is an HTTP server. The servlet container can serve static and dynamic content, mainly used where there is a requirement of communication between one machine to another. Customization of the jetty server can be done using an application.properties file.
To avoid conflict between the servers while using the jetty server, first, make sure that the default server Tomcat is excluded from the spring boot starter web. We need to add the spring-boot-starter-jetty dependency in our pom.xml file. We can find the updated pom.xml file below.
<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>
You can also try this code with Online Java Compiler
Run CodeUndertow server
The Undertow server is an embedded web similar to a jetty server. It is written in Java. Unlike other embedded servers, the undertow server supports HTTP/2, HTTP upgrade support, WebSocket support, etc. It is also flexible. Customization of the undertow server can be done using an application.properties file.
To avoid conflict between the servers while using the undertow server, first, make sure that the default server Tomcat is excluded from the spring boot starter web. We can find the updated pom.xml file below.
<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>
You can also try this code with Online Java Compiler
Run CodeWhat makes spring boot starter web different from spring boot starter tomcat?
Spring boot starter tomcat is included in spring web dependencies. The spring web dependencies are present in the spring boot starter web. The spring boot starter web contains spring boot starter, Jackson, spring core, spring MVC, spring boot starter tomcat.
Core, el, logging, and WebSocket are present in the spring boot starter tomcat.
We can use Spring MVC without an embedded tomcat server. To do this, we have to exclude the Tomcat server using the <extension>
The dependencies present in the starter tomcat are:
<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>
You can also try this code with Online Java Compiler
Run CodeFAQs
- What are the advantages of spring boot?
Spring boot helps create standalone applications without using an external web server. It allows us to use embedded servers such as Tomcat, undertow, or jetty.
- What are the important features of using a spring boot?
Some of the important spring boot features are starter dependency, auto-configuration, and spring initializer.
- What is a spring boot admin?
Spring Boot Admin is a web application. It is used for managing and monitoring Spring Boot applications.
Key takeaway
Spring boot helps to create standalone applications. They do not require an external web server. They have an embedded server. The server is embedded as a part of the deployable application. The default embedded server is called Tomcat. Other embedded systems supported apart from default are the Jetty server and the Undertow server. We have seen what a spring boot starter web is. We have looked at the different server types like the Spring boot embedded server, the Undertow server. We have also looked at how the Spring boot web server is different from the Tomcat server.
Recommended Readings: