想要替换starter中的某些依赖,可以先exclude那个依赖,然后在pom.xml中添加你要用的依赖。

    1. <dependencies>
    2. <dependency>
    3. <groupId>org.springframework.boot</groupId>
    4. <artifactId>spring-boot-starter-web</artifactId>
    5. <!--web 起步依赖环境中,排除 Tomcat 起步依赖 -->
    6. <exclusions>
    7. <exclusion>
    8. <groupId>org.springframework.boot</groupId>
    9. <artifactId>spring-boot-starter-tomcat</artifactId>
    10. </exclusion>
    11. </exclusions>
    12. </dependency>
    13. <!-- 添加 Jetty 起步依赖,版本由 SpringBoot 的 starter 控制 -->
    14. <dependency>
    15. <groupId>org.springframework.boot</groupId>
    16. <artifactId>spring-boot-starter-jetty</artifactId>
    17. </dependency>
    18. <dependency>
    19. <groupId>org.springframework.boot</groupId>
    20. <artifactId>spring-boot-starter-test</artifactId>
    21. <scope>test</scope>
    22. </dependency>
    23. </dependencies>

    上面我们用jetty替换tomcat。Jetty比Tomcat更轻量级,可扩展性更强(相较于Tomcat),谷歌应用引擎(GAE)已经全面切换为Jetty

    • SpringBoot内置服务器
      • tomcat(默认) apache出品,粉丝多,应用面广,负载了若干较重的组件
      • jetty 更轻量级,负载性能远不及tomcat
      • undertow:负载性能勉强跑赢tomcat

    小结:
    内嵌Tomcat服务器是SpringBoot辅助功能之一
    内嵌Tomcat工作原理是将Tomcat服务器作为对象运行,并将该对象交给Spring容器管理
    变更内嵌服务器思想是去除现有服务器,添加全新的服务器