1.设置<packaging>war</packaging>

2.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- 移除嵌入式tomcat插件打包WAR时-->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>

</dependency>
<!--打包WAR时需要这个-->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

3.IDEA Spring boot maven 打包WAR包

@SpringBootApplication
public class DemoApplication  extends SpringBootServletInitializer {

    //添加扩展extends SpringBootServletInitializer用于WAR包
    //重写configure方法


    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    // 重写 configure方法
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
    {
        return application.sources(DemoApplication.class);
    }
}

4.IDEA Spring boot maven 打包WAR包

5.OK

相关文章:

  • 2022-12-23
  • 2021-10-27
  • 2021-04-01
  • 2020-04-01
  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
猜你喜欢
  • 2018-05-01
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2021-04-15
  • 2021-12-16
相关资源
相似解决方案