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下详细教程

时间: 2024-07-30 10:07:18

SpringBoot发布WAR启动报错:Error assembling WAR: webxml attribute is required的相关文章

springboot启动报错:&quot;Error starting ApplicationContext. To display the conditions report re-run your application with &#39;debug&#39; enabled.&quot;

报错内容 java.lang.Object.wait(Native Method)java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:41)2019-02-14 14:58:00.326 INFO 17688 --- [ main] Condition

源码安装mysql5.6x启动报错:[ERROR] Can&#39;t find messagefile &#39;/data/mysqldata/3306/english/errmsg.sys&#39;

170502 10:43:40 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data 2017-05-02 10:43:40 0 [Warning] The syntax '--language/-l' is deprecated and will be removed in a future release. Please use '--lc-messages-dir' instead.

nodejs express 启动报错 Error Cannot find module &#39;xxx&#39;

nodejs express 启动报错:Error: Cannot find module 'xxx',这是因为缺少模块的引用. 比如我在代码中使用了'express-session',但是却没有在 package.json 文件的 "dependencies" 项中添加 'express-session' 的依赖 D:\nodejs\myapp>set DEBUG=myapp & npm start > myapp@0.0.0 start D:\nodejs\my

008-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-b

mysql登陆启动报错 ERROR 2002 (HY000) 解决方法

报错信息 登陆数据库报错:` ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory")` 重启服务报错:Job for mariadb.service failed because the control process exited with error code. See &quo

springboot多数据源启动报错:required a single bean, but 6 were found:

技术群: 816227112 参考:https://stackoverflow.com/questions/43455869/could-not-autowire-there-is-more-than-one-bean-of-datasource-type Parameter 0 of method redisTemplate in org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration required

IntelliJ IDEA 14.1.4导入项目启动报错:Error during artifact deployment.[组件部署期间出错]

1.问题描述:Error during artifact deployment.[组件部署期间出错] 2.删除Artifacts 3.刷新 4.重新生成Artifacts 5.重新选择 再重新启动项目即可.

Rabbitmq 服务启动后停止 | Windows下启动报错Error: unable to connect to node [email&#160;protected]: nodedown

1.erlang版本和rabbitmq版本不匹配 版本匹配: http://www.rabbitmq.com/which-erlang.html 2.找到匹配的版本,卸载当前rabbitmq重新安装. 执行以下操作从计算机中完全卸载RabbitMQ和Erlang: (1)打开Windows控制面板,双击“程序和功能”. (2)在当前安装的程序列表中,右键单击RabbitMQ Server,然后单击“卸载”. (3)在当前安装的程序列表中,右键单击“Erlang OTP”,然后单击“卸载”. (4

android sdk启动报错error: could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037:

问题原因:端口5037被占用 解决方案: 方式一:可以用cmd命令 C:\Users\Administrator>netstat-ano | findstr "5037"                 <<<<<-------------查看5037 被谁占用,然后杀掉 TCP   127.0.0.1:5037        0.0.0.0:0             LISTENING       4524 TCP   127.0.0.1:503