zoukankan      html  css  js  c++  java
  • cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'.

    笔者最近学习一些spring mvc,在复制别人代码的时候报这个错。报错来源web.xml,原因是不符合xsd对xml的约束

    源文件

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        id="WebApp_ID" version="3.0">
    
        <servlet>
            <!--名称 -->
            <servlet-name>springmvc</servlet-name>
            <!-- Servlet类 -->
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>   
            <!-- 启动顺序,数字越小,启动越早 -->
            <load-on-startup>1</load-on-startup>  
            <init-param>
                <!--SpringMVC配置参数文件的位置 -->
                <param-name>contextConfigLocation</param-name>
                <!--默认名称为ServletName-servlet.xml -->
                <param-value>classpath*:springmvc-servlet.xml</param-value>
            </init-param>              
        </servlet>
    
        <!--所有请求都会被springmvc拦截 -->
        <servlet-mapping>
            <servlet-name>springmvc</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    
    </web-app>

    解决方法:

    调整<load-on-startup>节点的顺序,放到</servlet>之前,修改后的web.xml如下

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        id="WebApp_ID" version="3.0">
    
        <servlet>
            <!--名称 -->
            <servlet-name>springmvc</servlet-name>
            <!-- Servlet类 -->
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>   
            <init-param>
                <!--SpringMVC配置参数文件的位置 -->
                <param-name>contextConfigLocation</param-name>
                <!--默认名称为ServletName-servlet.xml -->
                <param-value>classpath*:springmvc-servlet.xml</param-value>
            </init-param>
            <!-- 启动顺序,数字越小,启动越早 -->
            <load-on-startup>1</load-on-startup>        
        </servlet>
    
        <!--所有请求都会被springmvc拦截 -->
        <servlet-mapping>
            <servlet-name>springmvc</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    
    </web-app>
  • 相关阅读:
    HashSet源码分析
    Mysql的体系结构和存储引擎
    触发器
    存储过程和函数
    索引
    SpringBoot 中的日志使用
    log4j2
    Logback
    slf4j
    日志门面
  • 原文地址:https://www.cnblogs.com/passedbylove/p/7525846.html
Copyright © 2011-2022 走看看