# pom package 改为 war
<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 依赖
<dependency> | |
<groupId>javax.servlet</groupId> | |
<artifactId>javax.servlet-api</artifactId> | |
<version>3.1.0</version> | |
<scope>provided</scope> | |
</dependency> |
# 添加 war 插件
<build> | |
<plugins> | |
<plugin> | |
<artifactId>maven-war-plugin</artifactId> | |
<version>2.6</version> | |
<configuration> | |
<!-- 如果想在没有 web.xml 文件的情况下构建 WAR,请设置为 false。--> | |
<failOnMissingWebXml>false</failOnMissingWebXml> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> |
# 修改 spring boot 启动类
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.boot.builder.SpringApplicationBuilder; | |
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | |
import org.springframework.cache.annotation.EnableCaching; | |
@SpringBootApplication | |
@EnableCaching | |
public class DemoApplication extends SpringBootServletInitializer { | |
public static void main(String[] args) { | |
SpringApplication.run(DemoApplication.class, args); | |
} | |
@Override | |
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | |
return application.sources(DemoApplication.class); | |
} | |
} |
# 打包
mvn clean package