nvalid content was found starting with element 'init-param'.

奇怪的web.xml配置错误

奇怪的web.xml配置错误

为org.springframework.web.servlet.DispatcherServlet设置参数contextConfigLocation自定义spring配置文件的位置,设置完后如下:

1
2
3
4
5
6
7
8
9
< servlet >
     < servlet-name >spring</ servlet-name >
     < servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class >
     < load-on-startup >1</ load-on-startup >
     < init-param >
         < param-name >contextConfigLocation</ param-name >
         < param-value >/WEB-INF/spring-servlet.xml</ param-value >
     </ init-param >
</ servlet >

直接部署运行没有问题,但是用eclipse打开就在第5行处报错:

1
2
3
4
5
Description Resource Path Location Type
cvc-complex- type .2.4.a: Invalid content was found starting with element 'init-param' .
One of '{ "http://java.sun.com/xml/ns/javaee" :enabled, "http://java.sun.com/xml/ns/javaee" :async-supported,
"http://java.sun.com/xml/ns/javaee" :multipart-config}' is expected.

将配置文件改为:

1
2
3
4
5
6
7
8
9
< servlet >
     < servlet-name >spring</ 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 >

eclipse就不报怨了,init-param要紧跟servlet-class元素吗?没这规定吧!
是tomcat太宽松了还是eclipse太严格了呢?!

===
首先他们无视于你,而后是嘲笑你,接着是批斗你,再来就是你的胜利之日。 —— 甘地

猜你喜欢

转载自blog.csdn.net/penghao_1/article/details/52954444