Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to learn Spring boot and I notice there are two options.

  1. spring-boot-starter-web - which according to the docs gives support for full-stack web development, including Tomcat and web-mvc

  2. spring-boot-starter-tomcat

Since #1 supports Tomcat why would one want to use #2?

What are the differences?

Thanks

like image 446
DavidR Avatar asked Oct 29 '15 16:10

DavidR


People also ask

Does spring boot starter web contains Tomcat?

Spring Boot Starter Tomcat is the default embedded container for Spring Boot Starter Web. We cannot exclude it while using web services. We can exclude it when we want to use another embedded container. It also supports Jetty Server and Undertow Server.

What is in spring boot starter web?

It is an HTTP server and Servlet container that has the capability of serving static and dynamic content. It is used when machine to machine communication is required. If we want to add the Jetty server in the application, we need to add the spring-boot-starter-jetty dependency in our pom. xml file.

What is the difference between spring boot starter and spring boot starter parent?

The spring-boot-starter is the Core starter and provides functionalities including auto-configuration support, logging and YAML.It defines spring-boot-dependencies as the parent pom .

Do you think you can use jetty instead of Tomcat in spring boot starter web?

73.11 Use Jetty instead of TomcatYou need to exclude those dependencies and include the Jetty one instead. Spring Boot provides Tomcat and Jetty dependencies bundled together as separate starters to help make this process as easy as possible. Example in Gradle: configurations { compile.


1 Answers

Since #1 supports Tomcat why would one want to use #2?

spring-boot-starter-web contains spring-boot-starter-tomcat. spring-boot-starter-tomcat could potentially be used on its own if spring mvc isn't needed (contained in spring-boot-starter-web).

Here is the dependency hierarchy of spring-boot-starter-web:

enter image description here

What are the differences?

spring-boot-starter-web contains spring web dependencies (including spring-boot-starter-tomcat):

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

spring-boot-starter-tomcat contains everything related to an embdedded tomcat server:

core
el
logging
websocket

What if you want to use spring mvc without the embedded tomcat server?

Just exclude it from the dependency:

<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> 
like image 123
ltalhouarne Avatar answered Sep 20 '22 04:09

ltalhouarne