I'm trying to learn Spring boot and I notice there are two options.
spring-boot-starter-web - which according to the docs gives support for full-stack web development, including Tomcat and web-mvc
spring-boot-starter-tomcat
Since #1 supports Tomcat why would one want to use #2?
What are the differences?
Thanks
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.
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.
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 .
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.
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
:
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With