1.设置<packaging>war</packaging>
2.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 移除嵌入式tomcat插件打包WAR时-->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--打包WAR时需要这个-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
3.
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
//添加扩展extends SpringBootServletInitializer用于WAR包
//重写configure方法
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
// 重写 configure方法
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
{
return application.sources(DemoApplication.class);
}
}
4.
5.OK