【问题标题】:I can't run my spring boot app because web.xml file is showing an error and I don't know why我无法运行我的 Spring Boot 应用程序,因为 web.xml 文件显示错误,我不知道为什么
【发布时间】:2022-08-24 00:31:54
【问题描述】:

我的 web.xml 文件显示错误,我不知道为什么。当我转到该文件时,它在第二行的单词“<web-app”上显示红色 x。当我将鼠标悬停在错误上时,它会在下面显示此消息。

在此行找到多个注释:

  • cvc-complex-type.4:属性 \'version\' 必须出现在元素 \'web-app\' 上。
  • 属性:
  • 元素中需要版本:
  • 网络应用代码:

这是我的 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\">
    <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.xml 的第二行显示了两个不同的错误。第一种错误是 语言服务器 第二类错误是 XML 问题.

  • 我认为您需要在开始标签中指定网络应用程序版本。 &lt;web-app version=\"2.4\" xmlns.......
  • @arooney88 您能否指定开始标签中的网络应用程序版本的外观?以下是基于您的建议的网络应用程序代码开头的外观。 &lt;web-app version=\"2.4\" 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\"&gt;我确实添加了版本,保存后仍然显示错误。

标签: java spring-boot web.xml


【解决方案1】:

我移动了版本并将其放在 xmlns 文件之后,然后我重新启动了我的项目并解决了错误。这是解决问题后新代码的样子。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4" 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">
    <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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-02
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    • 2021-04-06
    • 2019-04-08
    相关资源
    最近更新 更多