zoukankan      html  css  js  c++  java
  • Spring Boot项目打包成war包

    在pom.xml文件中,将打包方式改为war:

    <packaging>war</packaging>

     

    然后添加如下的Tomcat依赖配置,覆盖Spring Boot自带的Tomcat依赖:

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

     

     

    <build></build>标签内配置项目名(该配置类似于server.context-path=mrbird):

    ...
    <build>
      ...
      <finalName>mrbird</finalName>
    </build>
    ...

     

    添加启动类ServletInitializer:

    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.web.support.SpringBootServletInitializer;

    public class ServletInitializer extends SpringBootServletInitializer {
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(Application.class);
      }
    }

     

    其中Application为Spring Boot的启动类。

    准备完毕后,运行mvn clean package命令即可在target目录下生产war包:

     

     

  • 相关阅读:
    CSS
    人物
    CSS
    CSS
    概念- 工业4.0
    C#正则表达式
    六月定律
    c#中实现登陆窗口(无需隐藏)
    c#中关于String、string,Object、object,Int32、int
    一个快速找第k+1小的算法
  • 原文地址:https://www.cnblogs.com/7788IT/p/11626646.html
Copyright © 2011-2022 走看看