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. POI 按word模版生成合同并生成PDF

    功能需求:根据用户给的word版本合同文件.docx,实现模版替换功能. 如: 功能:支持段落和表格里的文字替换,还可以支持表格替换.如果需要段落需要换行用<br>隔开如:身份证<b ...

  2. 在oracle RAC 环境下用 PL/SQL Developer debug procedure 出现 hang 的情况

    现象描述: 用plsql developer 连接编译procedure 的时候都很正常.一旦开始Test进入Debug模式的时候就Hang住了. 初步猜测是没有权限,可是是DBA角色呀,如果没有权限 ...

  3. Android下常见的内存泄露 经典

    转自:http://www.linuxidc.com/Linux/2011-10/44785.htm 因为Android使用Java作为开发语言,很多人在使用会不注意内存的问题. 于是有时遇到程序运行 ...

  4. 基础7 面向对象进阶与socket编程

    1.静态方法(用得少)(解除某个函数跟类的关联,加了静态方法后,类便不能将类的参数传给静态方法函数了) class Dog(object): def __init__(self,name): @sta ...

  5. Xtrareport绘制行号

    需要是用事件beforePrint (在打印数据之前的事件) private void xrTableCell12_BeforePrint(object sender, System.Drawing. ...

  6. JS获取前一个页面

    document.referrer 可以得到上一个点击超连接进来的页面URL注意:只能访问服务器上页面使用,打开本地文件无效(为空字符串)

  7. mysql中count(*)和found_rows()的区别

    count(*)和found_rows()都可以用来求查询记录的数量 而count(*)往往单独使用,found_rows()却可以跟上前面一个查询,即select * from table limi ...

  8. 从零开始的全栈工程师——js篇2.18(js的运动)

    一.元素的 client offset scroll 三个系列 clientWidth / clientHeight / clientTop / clientLeftoffsetWidth / off ...

  9. Android 实现朋友圈有图片和视频

    最近开发比较烦,这个作为我第一篇博客吧. 效果就是图上的样子. 首先是布局文件,没什么就是一个RecycleView <android.support.v7.widget.RecyclerVie ...

  10. ARouter使用随记

    官方文档地址 其他配置 1.创建一个config.gradle ext{ isDebug = false //false:作为Lib集成存在, true:作为application组件存在 andro ...