第一步:
pom 文件排除内置 Tomcat 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
jar 包打包形式改为 war 包
第二步:
在 xxxApplication.java 同目录下,新增 ServletInitializer.java
package com.example.demo;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {return application.sources(DemoApplication.class);
}
}
结束。
来自 Spring Init 指南。