首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spring-boot-starter tomcat vs spring-boot-starter web

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

Stack Overflow用户
提问于 2015-10-29 16:32:45
回答 2查看 22.3K关注 0票数 32

我正在尝试学习Spring引导,我注意到有两种选择。

  1. spring-boot-stack web根据docs提供对完整堆栈web开发的支持,包括Tomcat和web-mvc。
  2. 弹簧启动-启动-猫

既然#1支持Tomcat,为什么要使用#2?

有什么不同吗?

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-29 16:36:09

既然#1支持Tomcat,为什么要使用#2?

spring-boot-starter-web包含spring-boot-starter-tomcat。如果不需要spring (包含在spring-boot-starter-tomcat中),那么可以单独使用spring-boot-starter-tomcat

下面是spring-boot-starter-web的依赖层次结构

有什么不同吗?

spring-boot-starter-web包含spring依赖项(包括spring-boot-starter-tomcat):

spring-boot-starter

jackson

spring-core

spring-mvc

spring-boot-starter-tomcat

spring-boot-starter-tomcat包含与经过加密的tomcat服务器相关的所有内容:

core

el

logging

websocket

如果您想使用spring而不使用嵌入式tomcat服务器呢?

只需将其从依赖项中排除:

代码语言:javascript
复制
<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>
票数 40
EN

Stack Overflow用户

发布于 2015-10-29 16:39:11

一个简单的答案是,并不是所有的web应用程序都是SpringMVC应用程序。例如,如果您希望使用JaxRS,可能您有使用RestTemplate的客户端应用程序,并且您喜欢它们的交互方式,这并不意味着您不能使用spring或嵌入式tomcat

下面是一个使用spring-boot-starter-tomcat但不使用spring-boot-starter-web的示例应用程序

使用spring-boot-starter-tomcat在春季引导中简单的泽西应用程序

https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-jersey

同样重要的是,在spring引导中,tomcat并不是嵌入式servlet容器的唯一选项。开始使用jetty也很容易。有了spring-boot-starter-tomcat,就可以很容易地将所有模块排除为一个模块,而如果它们都只是spring的一部分,那么就需要更多的工作来排除tomcat库来引入spring-boot-starter-jersey

代码语言:javascript
复制
<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>

我从另一个问题中复制了这段代码。

How to configure Jetty in spring-boot (easily?)

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33419823

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档