zoukankan      html  css  js  c++  java
  • 如何把Spring Boot打包成war

    Spring Boot 默认打包为jar,受公司发布系统限制,不允许上传jar包,需要转为war和zip包,因此在使用Spring Boot时需要转为war。

    实现方式:

    1、需要App类继承SpringBootServletInitializer,并重写“protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)” 方法。

    Starter.java 文件:

    @SpringBootApplication

     

    @ComponentScan("com.xxx.tour.settlement")

     

    public class Starter extends SpringBootServletInitializer {

     

     

        public static void main(String[] args) throws Exception {

     

            SpringApplication.run(Starter.class, args);

     

     

            System.setProperty("java.awt.headless", "false");

     

            Desktop.getDesktop().browse(new URI("http://127.0.0.1:8080"));

     

        }

     

     

        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
            return builder.sources(Starter.class);
        }

     

     

    }

    2、修改Site的pom文件

    <packaging>war</packaging>

     

    3、添加web.xml 文件

    如果出现web.xml is missing and <failOnMissingWebXml> is set to true 异常,需要添加web.xml 文件。

    Spring Boot  默认是可以不需要web.xml 的,公司框架要求需要web.xml 文件,会读取该文件下相关配置信息。

    此问题的解决办法:

    1. 在Site中找到 Deployment Descriptor 右键。

    2. 选择Generate Deployment Descriptor Stub

    这样就能生成src/main/webapp/WEB_INF/web.xml文件了。

  • 相关阅读:
    分布式进程
    T1008 选数 codevs
    P1364 医院设置 洛谷
    T1046 旅行家的预算 codevs
    T1164 统计数字 codevs
    codevs——T1860 最大数||洛谷——P1107 最大整数
    手动脱Mole Box V2.6.5壳实战
    手动脱FSG壳实战
    手动脱NsPacK壳实战
    手动脱UPX 壳实战
  • 原文地址:https://www.cnblogs.com/xiaocandou/p/8016281.html
Copyright © 2011-2022 走看看