0

Receiving this error from console:

*org.springframework.beans.factory.BeanDefinitionStoreException:  
    IOException parsing XML document from ServletContext resource
 [/WEB-    INF/spring-dispatcher-servlet.xml]; nested exception is   
 java.io.FileNotFoundException: Could not open ServletContext resource        
[/WEB-INF/spring-dispatcher-servlet.xml]*

That's the error I receive from:

      <?xml version="1.0" encoding="UTF-8"?>
   <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
id="WebApp_ID" version="2.5">
  <display-name>fj21-tarefas</display-name>
  <welcome-file-list>

        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>

      </welcome-file-list>
      <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>
      <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>
    </web-app>

projects folder

I doing

<init-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/spring-context.xml</param-value>
</init-param>

to change the default context from springmvc, but it is not working. Already took some advice here to write a servlet-name tag to the file name-context.xml convention, same error.

2
  • I think you should add file: before value. file:/WEB-INF/spring-context.xml Commented Mar 14, 2020 at 5:07
  • @HarshalKhachane It's gives me the previous error with this one now: _GRAVE: StandardWrapper.Throwable org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:/WEB-INF/spring-context.xml]; nested exception is java.io.FileNotFoundException: \WEB-INF\spring-context.xml _ Commented Mar 14, 2020 at 6:03

2 Answers 2

1

You should try changing the servlet name. Expected Spring web-context metadata XML file name should servletname-servlet.xml, this was expected filename till Spring 4, not sure if it is changed in spring 5. . As your servlet name is springmvc, filename should be springmvc-servlet.xml.

<servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/springmvc-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/app-name/*</url-pattern>
</servlet-mapping>
Sign up to request clarification or add additional context in comments.

3 Comments

The error keeps on.... ERROR ContextLoader:319 - Context initialization failed org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]
No just spring-context.xml and web.xml.
Would it be possible to share the codebase? May be on GitHub.
0

Make your web.xml look like this, taken straight from the Spring documentation:

<web-app>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-context.xml</param-value>
    </context-param>

    <servlet>
        <servlet-name>app</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>app</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>

2 Comments

param-value is null.
Give it a try :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.