项目打包成war包

1、将打包方式改成war

<packaging>war</packaging>

2、移除tomcat依赖或者将tomcat依赖scope改为provide

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-tomcat</artifactId>
  <scope>provided</scope>
</dependency>

3、springboot启动类继承org.springframework.boot.web.servlet.support.SpringBootServletInitializer,重写configure方法:

启动类继承SpringBootServletInitializer实现configure:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}

posted @ 2022-11-11 14:30  光芒依旧  阅读(95)  评论(0)    收藏  举报