如何把项目打成war包?

  • 打包war [1] controller层的pom.xml加入

 war
  • 打包war [2] 移除自带内置tomcat

    org.springframework.boot
    spring-boot-starter-web
    
    
        
            spring-boot-starter-tomcat
            org.springframework.boot
        
    

  • 打包war [3] 添加依赖


      javax.servlet
      javax.servlet-api
      3.1.0

  • 打包war [4]添加war包启动类
package com.dashan;

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

/**
 * @Author:Frank
 * @Date:2020/11/18 19:48
 */
public class WarStarterApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        //指向Application--springboot启动类
        return builder.sources(Application.class);
    }
}

maven install后,会在controller层的target文件看到打好的war包,放入tomcat就部署完成了

你可能感兴趣的:(如何把项目打成war包?)