设置 load-on-startup 时出错:cvc-complex-type.2.4.a Invalid content was found starting with element 'load

众所周知,当一个Servlet需要在容器初始化时就被加载的话,需要为其在web.xml中设置<load-on-startup>属性

<load-on-startup>1</load-on-startup>

中间的数字代表加载的优先级,如果是正数则容器初始化时加载,而且正数数值越小优先级最高。

但是我在手动为一个<servlet> 添加一个<load-on-start> 标签时出现了如下错误:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'load-on-startup'. One of '{"http://java.sun.com/xml/ns/javaee":display-name, "http://java.sun.com/xml/ns/javaee":icon, "http://java.sun.com/xml/
 ns/javaee":servlet-name}' is expected.

其实就是说要在前面加上http://java.sun.com/xml/ns/javaee
修改方法很简单,将

<web-app version="3.0" 
    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">

修改为如下即可

<web-app version="3.0" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance 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">

修改的部分就是在xmlns:xsi 里面加上了http://java.sun.com/xml/ns/javaee

posted @ 2018-04-15 12:41  _吟游诗人  阅读(127)  评论(0编辑  收藏  举报