nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml]

A.M :

I am new to Spring MVC and I have now this problem:

javax.servlet.ServletException: Servlet.init() for servlet [dispatcher] threw exception

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]

I have found several questions with the same title, but none of them solved my problem.

My Working directory is something like this:

enter image description here

And these are file in this project:

this is web.xml file:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>


  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>
      org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

</web-app>

this is dispatcher-servlet.xml file:

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

    <ctx:annotation-config></ctx:annotation-config>
    <ctx:component-scan base-package="com.Controllers"></ctx:component-scan>

</beans>

this is pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.GTU</groupId>
  <artifactId>GTU</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>GTU Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.1.8.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>4.1.8.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.36</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>GTU</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.7.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.20.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

What mistake do I have?

JB Nizet :

You should have src/main/java, src/main/resources, and src/main/webapp.

resources and webapp must not be under src/main/java. src/main/java is for Java source files.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]

spring boot FileNotFoundException: Could not open ServletContext resource [/WEB-INF/main-servlet.xml]

Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/applicationContext.xml]

Spring Boot exception: Could not open ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml]

Spring+ MyBatis+ mvn Project , java.io.FileNotFoundException: Could not open ServletContext resource [/classpath*:WEB-INF/myBatis-config.xml]

Failed to parse configuration class, nested exception is java.io.FileNotFoundException: Could not open resource [/test.properties]

FileNotFoundException : Could not open ServletContext resource [/WEB-INF/spring/root-context.xml]

Could not open ServletContext resource [/WEB-INF/applicationContext.xml]

Could not open ServletContext resource

Spring MVC - Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml];

Could not open ServletContext resource -- except there is no reference to the resource

"Could not open ServletContext resource" in test context

(Spring) class path resource exception java.io.FileNotFoundException

Error Could not open ServletContext resource in jUnit Testing Spring Integration

Integration Test - Could not Open ServletContext Resource /application/properties

Servlet Upload java.io.FileNotFoundException:

Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-mvc-crud-demo-servlet.xml]:

Error creating bean with name 'hibernate4AnnotatedSessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]:

java.io.FileNotFoundException Path to Resource incorrect

java.io.FileNotFoundException: class path resource

IO Exception java.io.FileNotFoundException: (File name too long)

Could not open ServletContext resource [/<NONE>] when upgrade spring-boot-actuator 1.2.5.RELEASE

java.io.FileNotFoundException: class path resource [WEB-INF/classes/library.properties] cannot be opened because it does not exist

java.io.FileNotFoundException: class path resource [application.properties]

Parsing of XML ServletContext resource BeanDefinitionStoreException

ClassPathXmlApplicationContext return FileNotFoundException exception when try to open beans xml file

Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException

Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: Transaction already active

Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: EntityManagerFactory is closed