<web-app> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>ssm3</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ssm3</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:service-context.xml</param-value> </context-param> </web-app>
这样写会报错:
The content of element type "web-app" must match "(icon?,display-
name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-
mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,resource-env-
ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)".
要按顺序来写,调整context-param和servlet的顺序就可以了:
<web-app> <display-name>Archetype Created Web Application</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:service-context.xml</param-value> </context-param> <servlet> <servlet-name>ssm3</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ssm3</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>