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>
  • 相关阅读:
    新版新概念英语14册(英音+美音)MP3打包下载
    最近学习目标
    本人兼职C#,WinForm ,数据库,MapXtreme, Arcgis Engine 相关的开发
    everything is good on
    人之惰性思考
    css hacks 以及解决办法
    hibernate学习(1)——核心接口
    【原】可关闭,可重播的flash弹出广告代码
    PNG在IE6下透明问题的解决办法
    JSP解压ZIP压缩文件
  • 原文地址:https://www.cnblogs.com/passedbylove/p/7525846.html
Copyright © 2011-2022 走看看