【问题标题】:Spring boot WAR size with different embedded servers具有不同嵌入式服务器的 Spring Boot WAR 大小
【发布时间】:2015-05-20 10:30:09
【问题描述】:

我正在用 spring-boot 做一些实验,我意识到当我使用嵌入式 Tomcat 服务器时,生成的 WAR 大小比我使用 Jetty 甚至具有相同其余依赖项的 Undertow 服务器时要小。

这怎么可能? ... 应该说 Undertow 和 Jetty 与 tomcat 相比应该是超轻量级的。

尺寸为:

Tomcat ~18Mb

Undertow ~21Mb

码头 ~24Mb

它们中的任何一个对我来说都太大了,因为这是虚拟的 REST 端点。 这些是我的依赖项:

    <dependencies>
        <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-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- <dependency> -->
        <!-- <groupId>org.springframework.boot</groupId> -->
        <!-- <artifactId>spring-boot-starter-tomcat</artifactId> -->
        <!-- </dependency> -->
        <!-- <dependency> -->
        <!-- <groupId>org.springframework.boot</groupId> -->
        <!-- <artifactId>spring-boot-starter-undertow</artifactId> -->
        <!-- </dependency> -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
<!--        <dependency> -->
<!--            <groupId>org.springframework.boot</groupId> -->
<!--            <artifactId>spring-boot-starter-test</artifactId> -->
<!--            <scope>test</scope> -->
<!--        </dependency> -->
    </dependencies>

【问题讨论】:

  • 您是否尝试解压缩 .war 文件并查看 /lib 文件夹以查看额外重量的来源?

标签: java tomcat spring-boot embedded-jetty undertow


【解决方案1】:

Spring Boot 包括三个示例应用程序,spring-boot-sample-jettyspring-boot-sample-tomcatspring-boot-sample-undertow,具有最少且几乎相同的功能。使用 Spring Boot 1.2.2.RELEASE,档案大小为:

  • spring-boot-sample-jetty - 12MB
  • spring-boot-sample-tomcat - 9.8MB
  • spring-boot-sample-undertow - 9.6MB

如您所见,Tomcat 和 Undertow 几乎相同,而 Jetty 工件要大约 20%。

大小差异的一个显着原因是 JSP 支持。 Undertow 不支持 JSP,Spring Boot 默认不包含 Tomcat 的 JSP 支持。大约 1.7MB 的基于 Jetty 的存档被用于 JSP 编译的 Eclipse Java 编译器占用。如果您想使用 Jetty 并且不使用 JSP,则可以排除 org.eclipse.jetty:jetty-jsp 依赖项。这会将基于 Jetty 的工件的大小减少到 8.8MB。

【讨论】:

  • 另外,当部署这些嵌入式应用服务器时,这如何增加应用大小?
猜你喜欢
  • 2021-08-18
  • 2014-11-17
  • 2015-09-30
  • 1970-01-01
  • 2016-07-22
  • 2019-10-11
  • 2021-05-18
  • 2017-04-07
  • 1970-01-01
相关资源
最近更新 更多