第一步: pom.xml中加入<packaging>war</packaging>
第二步:
排除内置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>
第三步: 加入servlet-api依赖 <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>
第四步: 启动类修改 @SpringBootApplication public class TestApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder build){ return build.sources(TestApplication.class); } public static ConfigurableApplicationContext context; public static void main(String[] args) { context = SpringApplication.run(TestApplication.class, args); } }
接下来使用maven打包