springBoot生成war包
springBoot默认的打包方式为jar,要改成war包需要进行以下配置:
1.在pom.xml文件中声明打包方式:
<packaging>war</packaging>
2.移除springBoot内置的tomcat
<!-- 打包war [2] 移除自带内置tomcat -->
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
3.添加依赖
<!--打war包【3】 添加依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
4.编写war包启动类
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
// 打war包4 增加war包启动类
public class WarStartApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
5.安装 install ,war包在target包下

浙公网安备 33010602011771号