web.xml文件报错:cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'.

时间:2022-12-06 13:23:34
<?xml version="1.0" encoding="UTF-8"?>  
<web-app  
        version="3.0"  
        xmlns="http://java.sun.com/xml/ns/javaee"  
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 

报错的servlet节点

 1   <servlet>
 2     <servlet-name>Spring</servlet-name>
 3     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 4     <load-on-startup>1</load-on-startup>
 5     <async-supported>true</async-supported>
 6     <init-param>
 7       <param-name>contextConfigLocation</param-name>
 8       <param-value>classpath:config/spring-servlet.xml</param-value>
 9     </init-param>
10   </servlet>

报错提示在第6行

错误提示内容:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'. One of '{"http://java.sun.com/xml/ns/javaee":run-as, "http://java.sun.com/xml/ns/javaee":security-
 role-ref, "http://java.sun.com/xml/ns/javaee":multipart-config}' is expected.

解决方法:

把4,5行放到9,10行之间,代码如下

 1   <servlet>
 2     <servlet-name>Spring</servlet-name>
 3     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 4     <init-param>
 5       <param-name>contextConfigLocation</param-name>
 6       <param-value>classpath:config/spring-servlet.xml</param-value>
 7     </init-param>
 8     <load-on-startup>1</load-on-startup>
 9     <async-supported>true</async-supported>
10   </servlet>