William Barron
William Barron

Reputation: 55

Strange Error with web.xml in Spring MVC

I have a strange error with my web.xml, though everything works as intended. Here is the error Eclipse gives:

cvc-complex-type.2.4.d: Invalid content was found starting with element 'load-on-startup'. No child element is expected at this point.

Here is the part of the xml that the error occurs in

<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <multipart-config>
        <max-file-size>10485760</max-file-size>
        <max-request-size>20971520</max-request-size>
        <file-size-threshold>5242880</file-size-threshold>
    </multipart-config> 
    <load-on-startup>1</load-on-startup>
</servlet>

And the error is given on the <load-on-startup>1</load-on-startup>

Is this just a case of Eclipse being strange? Or is there something I am missing?

Here is the full web.xml in case it is something not related to that part of the code at all

<?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">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>
    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <multipart-config>
            <max-file-size>10485760</max-file-size>
            <max-request-size>20971520</max-request-size>
            <file-size-threshold>5242880</file-size-threshold>
        </multipart-config> 
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>  
</web-app>

Upvotes: 0

Views: 1451

Answers (1)

Amit Parashar
Amit Parashar

Reputation: 1457

Change the sequence of tag . This should be fine.

 <load-on-startup>1</load-on-startup>
  <multipart-config>
       <max-file-size>10485760</max-file-size>
       <max-request-size>20971520</max-request-size>
       <file-size-threshold>5242880</file-size-threshold>
   </multipart-config> 

Upvotes: 2

Related Questions