开发中总会因为一些原因,需要使用到 war 包来部署项目。
SpringBoot 如何打 war 包
- 修改 pom 依赖
<packaging>war</packaging> <!--打war包专属依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
- 修改启动入口(Application同级目录新建 SpringStarter.class)
public class SpringStarter extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(Application.class); } }