Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...