【发布时间】:2015-04-18 08:08:51
【问题描述】:
一个简单的 Spring Boot 应用程序在打包为可部署的 WAR 时仅打印“Hello World”,大小为 11.5 MB。当我分解 WAR 时,web-inf/lib 文件夹是库太多的根本原因。
- 如何仅使用最少的必要/依赖库来创建 WAR?
- 在提到 provided 作为 spring-boot-starter-tomcat 的范围时,嵌入式 Tomcat 服务器是否仍然与 WAR 一起打包?
我在玩 Spring 测试套件 (STS) 附带的“gs-spring-boot-complete”项目,这里是它附带的默认 POM。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-spring-boot</artifactId>
<version>0.1.0</version>
<!-- ... -->
<packaging>war</packaging>
<!-- ... -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.10.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- tag::actuator[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- end::actuator[] -->
<!-- tag::tests[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- end::tests[] -->
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
更新: 我从 POM 中删除了对 spring-boot-starter-tomcat 和 spring-boot-starter-actuator 的依赖,但 WAR 仍然是 11.5兆。
目前只有2个直接依赖spring-boot-starter-web & spring-boot-starter-test (我知道这可能反过来有其他依赖项)。
我的问题是,即使我不打算使用嵌入式 Tomcat 容器,“Spring Boot”应用程序会产生如此巨大的 可部署的 WAR ?我试图确认是否有任何事情 可以做一个优化的(我的意思是小型的)可部署的 WAR。
【问题讨论】:
标签: spring maven spring-boot