You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot应用启动失败:web.xml文件<web-app>标签报错求助

解决Spring Boot应用因web.xml缺少version属性无法启动的问题

核心错误为cvc-complex-type.4: Attribute 'version' must appear on element 'web-app',本质是你使用的J2EE 2.4规范对应的XML schema要求<web-app>标签必须显式声明version属性,缺少该属性会导致XML校验失败,进而阻断Spring Boot应用启动。

修改后的web.xml代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
         id="WebApp_ID"
         version="2.4">
    <display-name>springboot-server</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>

说明:你引用的是web-app_2_4.xsd,因此version属性值需设置为2.4,与schema版本匹配,这样XML校验就能通过,Spring Boot应用可正常启动。

内容的提问来源于stack exchange,提问作者Jean Baptiste Asong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 21:09:25