1、首先修改pom.xml文件
增加:
<packaging>war</packaging>
修改依赖,添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
2、修改启动类,继承SpringBootServletInitializer,重写方法configure。
public class PortalBackApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(PortalBackApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(PortalBackApplication.class);
}
}
3、执行mvn package命令,打包成功。