zoukankan      html  css  js  c++  java
  • SpringBoot发布WAR启动报错:Error assembling WAR: webxml attribute is required

    Spring Boot发布war包流程:

    1、修改web model的pom.xml

    <packaging>war</packaging>

    SpringBoot默认发布的都是jar,因此要修改默认的打包方式jar为war

    2、修改web model的依赖(dependency)

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <!-- 移除嵌入式tomcat插件,或者scope = provided
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>
                -->
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
    
            <!--<dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <scope>provided</scope>
            </dependency>-->

    注意:

    这里添加了起步依赖spring-boot-starter-web,因此,建议把起步依赖Spring-boot-starter-tomcat的scope设置为provided,原因很简单:我们的项目中可能会使用Filter等Servlet的api;

    因此,不建议spring-boot-starter-web中移除嵌入式Spring-boot-starter-tomcat的起步依赖,因为这样就必须再单独添加servet-api的依赖

    3、maven编译

    不解释

    启动时报错:Error assembling WAR: webxml attribute is required

    很明显:webapp/WEB-INF下找不到web.xml

    使用Spring开发,默认把所有的静态资源+界面view都放在resources下了,如下图:

    因此,webapp都不复存在了,更何况/WEB-INF和/WEB-INF/web.xml

    解决方案:

                <!-- 没有web.xml文件的情况下构建WAR
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
                -->
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <!--如果想在没有web.xml文件的情况下构建WAR,请设置为false。-->
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>

    1、使用maven-war-plugin3.0,解决了web.xml不存在无法构建war的问题

    2、继续使用maven-war-plugin2.6,添加设置failOnMissingWebXml=false

    搞定!

    ================================华丽的分割线====================================

    但是,强烈不建议使用SpringBoot发布war包,原因有三:

    1、默认的SpringBoot支持静态资源以jar包的方式发布部署

    2、前后端分离,后端使用SpringBoot开发,前段就无所谓了,完全可以不依赖SpringBoot

    3、在服务端加入Swagger插件,直接通过接口做测试,无需web界面

     

    参考:

     spring boot 用war包部署到tomcat下详细教程

  • 相关阅读:
    could not load file or assembly "System.Web.Mvc...
    .Net利用cwbx.dll call AS400 program得到数据
    fastadmin 如何构建组合题--Cannot read property '0' of undefined
    fastadmin的前端js文件中api和event的区别,formatter的意思
    fastadmin是如何使用art-template的,以及如何在js模板中,嵌套JS模板
    学习fastadmin的新技巧:去git里面看文件的修改
    thinphp5,模型调用模型,和控制器调用模型的区别
    fa使用技巧+tp5技巧总结
    input autocomplete的作用是什么?
    fastadmin 实现标签的多选研究---基于fa的test案例,已经CMS中的标签写法
  • 原文地址:https://www.cnblogs.com/huahua035/p/7808176.html
Copyright © 2011-2022 走看看