IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Web Java Discussion :

IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml] [MVC]


Sujet :

Spring Web Java

  1. #1
    Membre à l'essai
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2009
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Septembre 2009
    Messages : 20
    Points : 13
    Points
    13
    Par défaut IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]
    Bonjour,

    Je suis débutant avec Spring MVC. Le projet compile normalement, mais j'ai l'erreur ci-dessous lors du déploiement sur Tomcat 8.5.

    org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:612)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:513)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4763)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5232)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1429)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:831)
    Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
    at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
    ... 21 more
    - web.xml

    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    <?xml version="1.0" encoding="UTF-8"?>
    <!--https://stackoverflow.com/questions/3219639/cvc-id-3-error-in-web-xml-->
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://java.sun.com/xml/ns/javaee" 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>Mvc</display-name>
     
      <listener>
        <listener-class>
        	org.springframework.web.context.ContextLoaderListener
        </listener-class>
      </listener>
     
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
      </context-param>
     
     
     
      <welcome-file-list>
        <welcome-file>connexion.jsp</welcome-file>
      </welcome-file-list>
     
      <servlet>
        <description></description>
        <display-name>ConnexionServlet</display-name>
        <servlet-name>ConnexionServlet</servlet-name>
        <servlet-class>com.springmvc.controller.ConnexionServlet</servlet-class>
        <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>/WEB-INF/applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
     
      <servlet-mapping>
        <servlet-name>ConnexionServlet</servlet-name>
        <url-pattern>/ConnexionServlet</url-pattern>
      </servlet-mapping>
     
      <servlet>
        <description></description>
        <display-name>DeconnexionServlet</display-name>
        <servlet-name>DeconnexionServlet</servlet-name>
        <servlet-class>com.springmvc.controller.DeconnexionServlet</servlet-class>
      </servlet>
     
      <servlet-mapping>
        <servlet-name>DeconnexionServlet</servlet-name>
        <url-pattern>/DeconnexionServlet</url-pattern>
      </servlet-mapping>
     
    </web-app>

    - /resources/beans.xml

    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- beans.xml -->
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" 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  http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-3.0.xsd">
       <context:component-scan base-package="com.springmvc" />
       <context:annotation-config />
       <bean id="articleService" class="com.springmvc.service.ArticleServiceImpl" />
       <bean id="clientService" class="com.springmvc.service.ClientServiceImpl" />
       <bean id="commanderService" class="com.springmvc.service.CommanderServiceImpl" />
       <bean id="MySQLConnection" class="com.springmvc.service.MySQLConnection">
          <property name="driverClassName" value="com.mysql.jdbc.Driver" />
          <property name="url" value="jdbc:mysql://localhost:3306/name_database" />
          <property name="username" value="root" />
          <property name="password" value=" " />
       </bean>
       <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
          <!-- Maximum Upload Size (In Bytes) -->
          <property name="maxUploadSize" value="20971520" />
          <!-- Maximum Size Of The File In Memory (In Bytes) -->
          <property name="maxInMemorySize" value="1048576" />
       </bean>
    </beans>

    Pour info, MySQLConnection est une classe Java créée pour gérer l'authentification. Elle est instanciée dans les classes DAO.

    /resources/applicationContext.xml

    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- spring-mvc-servlet.xml -->
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" 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  http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-3.0.xsd  http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
       <import resource="classpath:/beans.xml" />
       <context:component-scan base-package="com.springmvc" />
       <context:annotation-config />
       <mvc:resources mapping="/resources/**" location="/resources/theme/" cache-period="31556926" />
       <mvc:resources mapping="/images/**" location="/images/" />
       <mvc:annotation-driven />
       <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
       <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
       <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
       <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          <property name="prefix" value="/WEB-INF/jsp/" />
          <property name="suffix" value=".jsp" />
       </bean>
    </beans>

    - Mvc/pom.xml

    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- pom.xml -->
    <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>Mvc</groupId>
       <artifactId>mvc</artifactId>
       <version>0.0.1-SNAPSHOT</version>
       <packaging>war</packaging>
       <name>Mvc 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>
          <spring.version>4.3.2.RELEASE</spring.version>
          <junit.version>4.12</junit.version>
          <servlet.version>3.1.0</servlet.version>
          <servlet.version>3.0.1</servlet.version>
          <mysql.connector.version>5.1.9</mysql.connector.version>
          <maven.compiler.source>1.7</maven.compiler.source>
          <maven.compiler.target>1.7</maven.compiler.target>
       </properties>
       <dependencies>
          <!-- Junit -->
          <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>${junit.version}</version>
             <scope>test</scope>
          </dependency>
          <!--Servlet-Api -->
          <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>javax.servlet-api</artifactId>
             <version>${servlet.version}</version>
          </dependency>
          <!-- Spring Framework -->
          <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-core</artifactId>
             <version>${spring.version}</version>
          </dependency>
          <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-beans</artifactId>
             <version>${spring.version}</version>
          </dependency>
          <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-context</artifactId>
             <version>${spring.version}</version>
          </dependency>
          <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-jdbc</artifactId>
             <version>${spring.version}</version>
          </dependency>
          <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-test</artifactId>
             <version>${spring.version}</version>
             <scope>test</scope>
          </dependency>
          <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-webmvc</artifactId>
             <version>${spring.version}</version>
          </dependency>
          <!-- MySQL database driver -->
          <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
             <version>${mysql.connector.version}</version>
          </dependency>
          <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>jsp-api</artifactId>
             <version>2.0</version>
             <scope>provided</scope>
          </dependency>
          <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
          <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>jstl</artifactId>
             <version>1.2</version>
          </dependency>
          <dependency>
             <groupId>taglibs</groupId>
             <artifactId>standard</artifactId>
             <version>1.1.2</version>
          </dependency>
          <!-- FileUpload dependency -->
          <dependency>
             <groupId>commons-fileupload</groupId>
             <artifactId>commons-fileupload</artifactId>
             <version>1.4</version>
          </dependency>
          <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
          <dependency>
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
             <version>2.5</version>
          </dependency>
       </dependencies>
       <build>
          <finalName>Mvc</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.1.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.8.0</version>
                </plugin>
                <plugin>
                   <artifactId>maven-surefire-plugin</artifactId>
                   <version>2.22.1</version>
                </plugin>
                <plugin>
                   <artifactId>maven-war-plugin</artifactId>
                   <version>3.2.2</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>

    Svp, quels changements devrais-je faire ? Sinon quelle serait la meilleure façon de procéder ?
    Cordialement,

  2. #2
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Salut,

    On voit dans la stacktrace :
    java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml
    que le fichier applicationContext.xml n'est pas trouvé dans le dossier /WEB-INF.

    En effet tu indiques qu'il serait dans le dossier "/resources" et dans le web.xml tu indiques qu'il est doit être cherché par la bean factory dans "/WEB-INF" :

    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    le fichier doit être dans un sous dossier de WEB-INF et le context-param doit indiquer cet emplacement.
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2009
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Septembre 2009
    Messages : 20
    Points : 13
    Points
    13
    Par défaut
    Bonjour,
    En effet, j'ai pu le résoudre en déplaçant applicationContext dans /WEB-INF.
    Je note ton retour comme la convention à respecter.
    Cordialement,

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 12/12/2012, 12h16
  2. Réponses: 1
    Dernier message: 04/05/2011, 15h02
  3. [Erreur]Could not parse mapping document from resource
    Par Le Pharaon dans le forum Hibernate
    Réponses: 5
    Dernier message: 17/06/2009, 10h53
  4. Réponses: 0
    Dernier message: 15/05/2009, 12h13
  5. erreur: Could not parse mapping document from resource
    Par ferrero dans le forum Hibernate
    Réponses: 1
    Dernier message: 16/05/2007, 19h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo