- 修改 Spring Boot 的 Application 类,使其继承 SpringBootServletInitializer 类,并重写 configure 方法:
@SpringBootApplication
public class CmsApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(CmsApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(CmsApplication.class, args);
}
}
- 修改项目构建配置文件:
Maven(pom.xml):
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Gradle(build.gradle):
apply plugin: 'war'
dependencies {
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}
- 执行打包命令:
Maven:
mvn clean package
Gradle:
gradle clean
gradle bootWar