How to solve BeanDefinitionStoreException: IOException parsing an XML document from a ServletContext resource [/WEB-INF/dispatcher-servlet.xml]?

Error Stack Trace:

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

dispatcher-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:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:beans="http://springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/task/spring-task.xsd"> <mvc:annotation-driven/> <context:component-scan base-package="com.exam.www" /> <!-- Factory bean that creates the Mongo instance --> <bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean"> <property name="host" value="localhost" /> </bean> <!-- MongoTemplate for connecting and quering the documents in the database --> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongo" ref="mongo" /> <constructor-arg name="databaseName" value="Results" /> </bean> <!-- Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes --> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp" p:suffix=".jsp" /> <!-- <bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver"/> <bean class= "org.springframework.web.servlet.view.tiles2.TilesConfigurer"> --> <!-- <property name="definitions"> <list> <value>/WEB-INF/views/views.xml</value> </list> </property> </bean> --> </beans> 

applicationContext.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!-- Root Context: defines shared resources visible to all other web components --> <!-- CSRF protection. Here we only include the CsrfFilter instead of all of Spring Security. See http://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#csrf for more information on Spring Security CSRF protection --> <!-- <bean id="csrfFilter" class="org.springframework.security.web.csrf.CsrfFilter"> <constructor-arg> <bean class="org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository"/> </constructor-arg> </bean> --> <!-- Provides automatic CSRF token inclusion when using Spring MVC Form tags or Thymeleaf. See http://localhost:8080/#forms and form.jsp for examples --> <!-- <bean id="requestDataValueProcessor" class="org.springframework.security.web.servlet.support.csrf.CsrfRequestDataValueProcessor"/> --> </beans> 

web.xml

 <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_2_5.xsd" version="2.5"> <!-- <display-name>Spring With MongoDB Web Application</display-name> --> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/dispatcher-servlet.xml</param-value> </context-param> <welcome-file-list> <welcome-file>/search.jsp</welcome-file> </welcome-file-list> </web-app> 

I tried several solutions on the Internet 1) Granting read and write permissions to all files - Does not work 2) Adding init-param - does not work 3) Explicitly providing the dispatch service path as / WebContent / WEB -INF / dispatcher-servlet.xml - not working.

I get this error when starting a project on Apache tomcat v7.0 server

I am struck by this problem for the last 4 days. Please help me.

The following is the solution that worked.

There is no dispatcher-servlet.xml in your war. 1) There is no webapp folder in the project. When you create a project using maven, remember. You can follow the steps given here http://blog.manishchhabra.com/2013/04/spring-data-mongodb-example-with-spring-mvc-3-2/ You would create a project using some strange maven archetype . Try the above link and it works.

I do not find this solution to others where on the Internet. :)

+7
java spring spring-mvc web
source share
4 answers

Spring creates two application contexts for a web application. The first is the root context of the application containing the beans application, for example, DAO service objects, etc. This context (applicationContext.xml in your case) is configured using context-param contextConfigLocation. The second is the context of the child web application containing your beans website. This is configured using the dispatch servlet init-paramConfiguration context.

In your case, you duplicated the configuration file for both. Change your web.xml as follows

 <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_2_5.xsd" version="2.5"> <!-- <display-name>Spring With MongoDB Web Application</display-name> --> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <welcome-file-list> <welcome-file>/search.jsp</welcome-file> </welcome-file-list> </web-app> 
+4
source share

Try changing <param-value>WEB-INF/dispatcher-servlet.xml</param-value> to <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> in web.xml

0
source share

Firstly, dispatcher-servlet.xml is a spring mvc configuration, this is not for the application. Therefore, you must delete <context-param> in your web.xml.

Then spring mvc will get the xml file according to the servlet manager. Thus, you can also remove the <init-param> tag in web.xml <servlet>.

try to see if spring mvc can find xml auto

0
source share

Replace the uri file mvc-config as shown below:

 <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/classes/dispatcher-servlet.xml</param-value> </context-param> 
-one
source share

All Articles