cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'

后端 未结 3 630
旧巷少年郎
旧巷少年郎 2020-12-03 00:38

This is my web.xml xsd


    

        
相关标签:
3条回答
  • 2020-12-03 01:03

    Configure according to this

      <?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">
    
          <listener>
                <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
            </listener>
    
            <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/dispatcher-servlet-context.xml</param-value>
            </context-param>
    
            <servlet>
                <servlet-name>dispatcher-servlet</servlet-name>
                <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                <init-param>
                    <param-name>contextConfigLocation</param-name>
                    <param-value></param-value>
                </init-param>
                <load-on-startup>1</load-on-startup>
            </servlet>
    
            <servlet-mapping>
                <servlet-name>dispatcher-servlet</servlet-name>
                <url-pattern>/*</url-pattern>
            </servlet-mapping>
    
        </web-app>
    
    0 讨论(0)
  • 2020-12-03 01:04

    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>
    
    0 讨论(0)
  • 2020-12-03 01:19

    It's pedantic, but <init-param> has to come before <load-on-startup>, so:

    <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>
    
    0 讨论(0)
提交回复
热议问题