cvc-complex-type.2.4.a:发现以元素“init-param"开头的无效内容 [英] cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'
问题描述
这是我的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节点
Here is servlet node
<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>
在标记的那一行 xml 验证器说
On the marked line xml validator says
cvc-complex-type.2.4.a:发现以元素init-param"开头的无效内容.'{"http://java.sun.com/xml/ns/javaee":启用, "http://java.sun.com/xml/ns/javaee":async-supported, "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}' 是预期的.
cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'. One of '{"http://java.sun.com/xml/ns/javaee":enabled, "http://java.sun.com/xml/ns/javaee":async-supported, "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.
出了什么问题,我该如何纠正这个错误?
What is wrong and how do I correct this error?
推荐答案
web.xml
中元素的顺序很重要,在我遇到的所有示例中,
在
之后.
The order of elements in web.xml
matters and in all examples I've come across, the <load-on-startup>
comes after <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>
这篇关于cvc-complex-type.2.4.a:发现以元素“init-param"开头的无效内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!