Uploaded image for project: 'Spring Tool Suite'
  1. Spring Tool Suite
  2. STS-4417

Getting nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/MyDemoApp-servlet.xml] Error [on hold]

    XMLWordPrintable

Details

    • Support
    • Status: Closed
    • Critical
    • Resolution: Works as Designed
    • 3.8.2.RELEASE
    • None
    • MAVEN, SUPPORT
    • None

    Description

      I am creating a simple Spring application, but when I am trying to run the application on the server it is giving me 500 error. Below I have provided my files: web.xml, the application context file and the error that I am getting. Why is the error occurring?

      web.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app 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"
      version="3.0">
      <display-name>My Demo App</display-name>
      <servlet>
      <servlet-name>MyDemoApp</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <init-param>
      <param-name>contextConfiguration</param-name>
      <param-value>/WEB-INF/config/myDemoApp-servlet.xml</param-value>
      </init-param>
      </servlet>
      <servlet-mapping>
      <servlet-name>MyDemoApp</servlet-name>
      <url-pattern>*.html</url-pattern>
      </servlet-mapping>
      </web-app>

      myDemoApp-servlet.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns="http://www.springframework.org/schema/p"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

      <mvc:annotation-driven/> <!--out application is annotion driven -->

      <context:component-scan base-package="com.zensar.controller"></context:component-scan> <!-- it will scan this this package for annotion-->

      <!-- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> ViewResolver interface is used to map view name with view page
      <property name="prefix" value="WEB-INF/jsp/"/> location as prefix
      <property name="suffix" value=".jsp"/> type of view
      </bean> -->

      <!-- p namespace is an alternative to using the property tag. -->
      <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="WEB-INF/jsp/" p:suffix=".jsp"/>

      </beans>

      So when I am trying to run this application on server I am getting the below error:

      HTTP Status 500 - Servlet.init() for servlet MyDemoApp threw exception
      --------------------------------------------------------------------------------
      type Exception report
      message Servlet.init() for servlet MyDemoApp threw exception
      description The server encountered an internal error that prevented it from fulfilling this request.
      exception
      javax.servlet.ServletException: Servlet.init() for servlet MyDemoApp threw exception
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:745)
      root cause
      org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/MyDemoApp-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/MyDemoApp-servlet.xml]
      org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)
      org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
      org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
      org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
      org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
      org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
      org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
      org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
      org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      javax.servlet.GenericServlet.init(GenericServlet.java:158)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:745)
      root cause
      java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/MyDemoApp-servlet.xml]
      org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
      org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
      org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
      org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
      org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
      org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
      org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
      org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
      org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
      org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      javax.servlet.GenericServlet.init(GenericServlet.java:158)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:745)

      Attachments

        1. webxml.PNG
          webxml.PNG
          39 kB
        2. dispatcher-servlet.PNG
          dispatcher-servlet.PNG
          54 kB
        3. file-structure.PNG
          file-structure.PNG
          20 kB

        Activity

          People

            Unassigned Unassigned
            rahulborserb Rahul Ramesh Borse
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: