我的所有 XML 个 SpringMVC 项目的配置文件显示一些错误,他们无法识别文件中的符号

My all XML configuration files of SpringMVC project show some error that they can't recognize the symbol in the files

不知道这些错误是怎么产生的,刚才的项目没有任何问题。

我记得我重命名了 index.jsp 并创建了一个新的 RestController。

错误说 "Element param-serviceName is not allowed here"。

这里有一些图片显示了错误

web.xml:

applicationContext.xml:

和web.xml的代码如下,其他xml文件如web.xml

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
     http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
     version="3.1">

<!--配置Spring核心监听器-->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!--指定Spring的配置文件-->
<context-param>
    <param-serviceName>contextConfigLocation</param-serviceName>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<!--Spring MVC的前端控制器-->
<servlet>
    <servlet-serviceName>springmvc</servlet-serviceName>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-serviceName>contextConfigLocation</param-serviceName>
        <param-value>/WEB-INF/springmvc-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <multipart-config>
        <!--临时文件的目录-->
        <location>/tmp/</location>
        <!-- 上传文件最大2M -->
        <max-file-size>2097152</max-file-size>
        <!-- 上传文件整个请求不超过4M -->
        <max-request-size>4194304</max-request-size>
    </multipart-config>
</servlet>
<servlet-mapping>
    <servlet-serviceName>springmvc</servlet-serviceName>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<!--编码过滤器-->
<filter>
    <filter-serviceName>characterEncodingFilter</filter-serviceName>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-serviceName>encoding</param-serviceName>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-serviceName>forceEncoding</param-serviceName>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-serviceName>characterEncodingFilter</filter-serviceName>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!--session有效时间-->
<session-config>
    <session-timeout>30</session-timeout>
</session-config>

认为这是我的错误,无法正确帮助 OP

您的 web.xml 中的问题是,它使用了错误的标签。

将您的 web.xml 更新到此,然后尝试。

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
     http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <!--配置Spring核心监听器-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!--指定Spring的配置文件-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <!--Spring MVC的前端控制器-->
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/springmvc-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <multipart-config>
            <!--临时文件的目录-->
            <location>/tmp/</location>
            <!-- 上传文件最大2M -->
            <max-file-size>2097152</max-file-size>
            <!-- 上传文件整个请求不超过4M -->
            <max-request-size>4194304</max-request-size>
        </multipart-config>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!--编码过滤器-->
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!--session有效时间-->
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
</web-app>