spring+springMVC配置时发生 org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors错误
在启动Tomcat时没有响应,错误信息如下:
严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors
经检查,发现是web.xml配置文件中context-parm标签配置错了:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>contextConfigLocationValue></param-value>
</context-param>
这里classpath的值应该是spring.xml而不是springmvc.xml
原因是springmvc的监听器要加载类路径下的配置文件,即spring的配置文件
改之,重新运行Tomcat,成功加载页面。
补:web.xml代码:
<web-app>
<!-- 配置加载类路径的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<!-- 配置过滤器:解决中文乱码 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置Spring的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置核心控制器 -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 使核心控制器初始化时读取bean.xml文件创建Spring核心容器 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<!-- 设置该Servlet的优先级别未最高,使之最早创建 -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
在springmvc的核心控制器中也有个init-param,其classpath的值应为springmvc.xml(不要混淆)
关于web.xml的加载过程,可以参考:
https://www.cnblogs.com/yaoyiyao/p/7198076.html
- web.xml 初始化过程: