spring+springMVC配置时发生 org.apache.catalina.core.StandardContext.startInternal Context [] startup fail

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>contextConfigLocationparam-name>  
<param-value>contextConfigLocationValue>param-value>  
context-param>  

这里classpath的值应该是spring.xml而不是springmvc.xml
原因是springmvc的监听器要加载类路径下的配置文件,即spring的配置文件
改之,重新运行Tomcat,成功加载页面。
spring+springMVC配置时发生 org.apache.catalina.core.StandardContext.startInternal Context [] startup fail_第1张图片
补:web.xml代码:

<web-app>
    
    <context-param>
        <param-name>contextConfigLocationparam-name>
        <param-value>classpath:spring.xmlparam-value>
    context-param>

    
    <filter>
        <filter-name>CharacterEncodingFilterfilter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
        <init-param>
            <param-name>encodingparam-name>
            <param-value>UTF-8param-value>
        init-param>
    filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilterfilter-name>
        <url-pattern>/*url-pattern>
    filter-mapping>

  
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
  listener>

  
  <servlet>
    <servlet-name>dispatcherServletservlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
    
    <init-param>
      <param-name>contextConfigLocationparam-name>
      <param-value>classpath:springmvc.xmlparam-value>
    init-param>
    
    <load-on-startup>1load-on-startup>
  servlet>
  <servlet-mapping>
    <servlet-name>dispatcherServletservlet-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 初始化过程:
    spring+springMVC配置时发生 org.apache.catalina.core.StandardContext.startInternal Context [] startup fail_第2张图片

你可能感兴趣的:(Java,SSM,Java,Spring,SpringMVC)