cvc-complex-type.2.4.a:从元素“init-param”开始find无效内容

这是我的web.xml xsd

 <?xml version="1.0" encoding="UTF-8"?> <web-app 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" version="3.0"> 

这里是servlet节点

 <servlet> <servlet-name>spring1</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> <init-param> <!-- here is a problem --> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-servlet.xml</param-value> </init-param> </servlet> 

在标记行xmlvalidation器说

cvc-complex-type.2.4.a:从元素“init-param”开始find无效的内容。 其中一个“{” http://java.sun.com/xml/ns/javaee “:启用,” http://java.sun.com/xml/ns/javaee “:asynchronous支持,” 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}”。

什么是错的,如何纠正这个错误?

web.xml中元素的顺序很重要,在我遇到的所有例子中, <load-on-startup>出现在<init-param>

 <servlet> <servlet-name>spring1</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> 

这是迂腐,但<init-param>必须在<load-on-startup> ,所以:

 <servlet> <servlet-name>spring1</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param><!--here is a problem--> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> 
Interesting Posts