Spring引导WAR大小与不同的嵌入式服务器

Raf*_*ael 4 java tomcat embedded-jetty spring-boot undertow

我正在使用spring-boot进行som实验,并且我意识到当我使用嵌入式Tomcat服务器时,生成的WAR大小比我使用Jetty甚至是具有相同其他依赖项的Undertow服务器时要小.

这怎么可能?...与tomcat相比,Undertow和Jetty应该是超轻型的.

尺码为:

Tomcat~18Mb

承诺~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>
Run Code Online (Sandbox Code Playgroud)

And*_*son 9

春季启动包括三个示例应用程序spring-boot-sample-jetty,spring-boot-sample-tomcat以及spring-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支持.~7.7MB的基于Jetty的存档由用于JSP编译的Eclipse Java编译器占用.如果要使用Jetty并且不使用JSP,则可以排除org.eclipse.jetty:jetty-jsp依赖项.这会将基于Jetty的工件的大小减小到8.8MB.