cvc-complex-type.2.4.a:从元素'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节点

<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验证器说

cvc-complex-type.2.4.a:从元素'init-param'开始发现无效内容 . 其中一个'{“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}'是预期的 .

有什么问题,如何更正此错误?

回答(2)

2 years ago

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>

2 years ago

它是迂腐的,但 <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>