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

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

  1. Tomcat7.0.40注册到服务启动报错error Code 1 +connector attribute sslcertificateFile must be defined when using ssl with apr

    Tomcat7.0.40 注册到服务启动遇到以下几个问题: 1.启动报错errorCode1 查看日志如下图: 解决办法: 这个是因为我的jdk版本问题,因为电脑是64位,安装的jdk是32位的所以会 ...

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

    android sdk启动报错error: could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037: 问题原因: ...

  3. 008-SpringBoot发布WAR启动报错:Error assembling WAR: webxml attribute is required

    一.Spring Boot发布war包流程: 1.修改web model的pom.xml <packaging>war</packaging> SpringBoot默认发布的都 ...

  4. 【maven 报错】maven项目执行maven install时报错Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)

    在使用maven新建的web项目中,执行 执行如上的这两个操作,报错: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-co ...

  5. springboot启动报错,Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

    报错: Error starting ApplicationContext. To display the conditions report re-run your application with ...

  6. tomcat启动报错 ERROR o.a.catalina.session.StandardManager 182 - Exception loading sessions from persiste

    系统:centos6.5 x86_64 jdk: 1.8.0_102 tomcat:8.0.37 tomcat 启动报错: ERROR o.a.catalina.session.StandardMan ...

  7. Tomcat启动报错ERROR:transport error 202:bind failed:Address already

    昨天在服务器上拷贝了一个tomcat项目,修改了server.xml之后启动居然报错ERROR:transport error 202:bind failed:Address already,应该是远 ...

  8. Springboot集成ES启动报错

    报错内容 None of the configured nodes are available elasticsearch.yml配置 cluster.name: fans node.name: no ...

  9. Idea启动报错 Error:java: System Java Compiler was not found in classpath

    报错信息:Error:java: System Java Compiler was not found in classpath 使用IDEA启动的时候出现了这个错误,查找了很久,才找到解决办法 1. ...

随机推荐

  1. Hidden Markov Models笔记

    Andrew Ng CS229 讲义: https://pan.baidu.com/s/12zMYBY1NLzkluHNeMNO6MQ HMM模型常用于NLP.语音等领域. 马尔科夫模型(Markov ...

  2. 性能测试工具LoadRunner11-LR之Virtual User Generator 移动app录制

    准备条件: 1.安装插件LR_03105_Patch4.EXE,安装完成之后就会有Mobile App(HTTP/HTML),如下截图所示 2.安装热点wifi,160wifi(注:有可能有的热点软件 ...

  3. [转]Tetris(俄罗斯方块) in jQuery/JavaScript!

    本文转自:http://pwwang.com/2009/10/25/tetris-in-jquery-javascript/ All in jQuery/JavaScript + HTML! Demo ...

  4. (转)sdd for aix 安装及基本命令

    总结出自多个文件(自己做的项目和网上找的资料) 原文:http://blog.csdn.net/yujin2010good/article/details/11395701 一.sddpcm安装 要安 ...

  5. 用信鸽来解释 HTTPS

    原文:http://blog.jobbole.com/113883/ ----------------------------------------------------------------- ...

  6. Java方法-对指定信息基于相关维度进行分组

    近期项目中需要针对多种不同来源指定的相同类型内容进行合并,实现过程中需要根据指定的相关维度,对资源内容进行分组,如识别是否可以为同一人员信息,是否为同一个歌曲或影视信息,因此针对实现的具体细节做如下备 ...

  7. php 可逆的加密算法

    代码: <?php class Test { private $authCodeKey = 'khUvFB9pijNyCYMGZdzqeKalyg7dh'; function authCode( ...

  8. POJ 3020——Antenna Placement——————【 最小路径覆盖、奇偶性建图】

    Antenna Placement Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  9. asp.net 单元测试(转)

    最早接触单元测试是看了极限编程相关资料里边讲的测试驱动开发,然后下载了Nunit研究了一下,但并没产生多大的触动,因为那个时候做的都是些时间紧任务重的事情,对于单元测试的直接感觉就是有可能比较费时间. ...

  10. java并发编程 volatile关键字 精准理解

    1.volatile的作用 一个线程共享变量(类的成员变量.类的静态成员变量等)被volatile修饰之后,就具有以下作用: 1)并发中的变量可见性(不同线程对该变量进行操作时的可见性),即一个线程修 ...