0

when I deploy my first Spring MVC application on Glassfish 4/ Tomcat 8 I'm getting this error

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

I think is a problem with my Servlet configuration.

web.xml

    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
  <display-name>MyDemoApp</display-name>
    <servlet>
  <servlet-name>myFirstSpring</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
  <param-name>contexConfiguration</param-name>
  <param-value>/WEB-INF/config/myDemoApp-servletConfig.xml</param-value>
  </init-param>
  </servlet>
  <servlet-mapping>
  <servlet-name>myFirstSpring</servlet-name>
  <url-pattern>*.html</url-pattern>
  </servlet-mapping>

</web-app>

my spring bean configuration file called myDemoApp-servletConfig.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"
    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></mvc:annotation-driven>

<context:component-scan base-package="com.demo.controllers"></context:component-scan>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="WEB=INF/jsp"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>][1]][1]

enter image description here

Any clue on what I have done wrong?

Sincerely,

SocketM
  • 564
  • 1
  • 19
  • 34

1 Answers1

0

Place myFirstSpring-servlet.xml in your WEB-INF folder. If you did and still not work, Clean your project and retry.

  • My configuration servlet is called myDemoApp-servletConfig.xml. The mapping is in init-params: contexConfiguration /WEB-INF/config/myDemoApp-servletConfig.xml – SocketM May 11 '18 at 15:11
  • declare the ContextLoaderListener in your web.xml and use a contextConfigLocation to set which context files to load. and then Change contextConfiguration to contextConfigLocation in the init-param and see if it works here is a link to check : https://stackoverflow.com/questions/6451377/loading-context-in-spring-using-web-xml – Elhoussine Zennati May 11 '18 at 15:24