1.去除Springboot自带Tomcat <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>
2.添加去除Tomcat之后少了的包 <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency>
3.Pom.xml文件 打包方式改为war <!--改为war方式 默认为jar--> <packaging>war</packaging>
4. 原启动类同路径下 创建war包启动类型 /** * @description: 打成war包后的外置war启动类 */ public class WarStarterApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(Application.class); } }
5.IDEA maven:先maven clean ,再install 生成war包(在项目路径下target文件夹中)