2017-03-16 1 views
0

Je ne suis pas en mesure de résoudre le problème.FileNotFoundException au printemps

stacktrace complète:

12:14:08.172 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence 
12:14:08.178 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence 
12:14:08.178 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment] 
12:14:08.183 [main] INFO o.s.c.s.ClassPathXmlApplicationContext - Refreshing org[email protected]24273305: startup date [Thu Mar 16 12:14:08 GMT 2017]; root of context hierarchy 
12:14:08.222 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence 
12:14:08.223 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence 
12:14:08.223 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment] 
12:14:08.233 [main] INFO o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [org/postprocessor/config/dataSupport.xml] 
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [org/postprocessor/config/dataSupport.xml]; nested exception is java.io.FileNotFoundException: class path resource [org/postprocessor/config/dataSupport.xml] cannot be opened because it does not exist 
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.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252) 
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127) 
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93) 
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.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 
at org.postprocessor.dao.DaoMain.main(DaoMain.java:12) 
Caused by: java.io.FileNotFoundException: class path resource [org/postprocessor/config/dataSupport.xml] cannot be opened because it does not exist 
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172) 
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330) 
... 13 more 

fichier de configuration Bean dataSupport.xml est ici:

<?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" 
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"> 

    <!-- <bean/> definitions here --> 
<context:annotation-config /> 
<context:component-scan base-package="org.postprocessor.dao" /> 
<context:component-scan base-package="org.postprocessor.model" /> 
<context:component-scan base-package="org.postprocessor.util" /> 



<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
    <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" 
     /> <property name="url" value="jdbc:derby:postprocessor;create=true;" /> 
<!-- <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" /> 
    <property name="url" value="jdbc:derby://localhost:1527/db;create=true;" /> --> 
    <property name="initialSize" value="1" /> 
    <property name="maxActive" value="1" /> 
</bean> 

<bean id="daoImpl" class="org.postprocessor.dao.DaoImpl" scope="prototype"> 
    <property name="dataSource" ref="dataSource" /> 
</bean> 

<bean id="messageSource" 
    class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basenames"> 
     <list> 
      <value>resourceBundles/general</value> 
      <value>resourceBundles/codeLists/codelist_eortcqlqc30</value> 
      <value>resourceBundles/codeLists/codelist_eortcqlqlc13</value> 
      <value>resourceBundles/codeLists/codelist_eq5d3l</value> 
      <value>resourceBundles/codeLists/codelist_eq5d5l</value> 
      <value>resourceBundles/codeLists/codelist_noncompletedquestionnaires</value> 
      <value>resourceBundles/codeLists/codelist_pgis</value> 
      <value>resourceBundles/codeLists/codelist_silc</value> 
     </list> 
    </property> 
</bean> 

Snipped de 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>SBP</groupId> 
<artifactId>SBP</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<name>gt20047</name> 
<packaging>jar</packaging> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-web</artifactId> 
     <version>4.3.1.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.17</version> 
    </dependency> 

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-asm --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-asm</artifactId> 
     <version>3.1.4.RELEASE</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/asm/asm-all --> 
    <dependency> 
     <groupId>asm</groupId> 
     <artifactId>asm-all</artifactId> 
     <version>3.3.1</version> 
    </dependency> 

    <!-- https://mvnrepository.com/artifact/org.apache.derby/derbynet --> 
    <dependency> 
     <groupId>org.apache.derby</groupId> 
     <artifactId>derbynet</artifactId> 
     <version>10.12.1.1</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/org.apache.derby/derbyclient --> 
    <dependency> 
     <groupId>org.apache.derby</groupId> 
     <artifactId>derbyclient</artifactId> 
     <version>10.12.1.1</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-jdbc</artifactId> 
     <version>2.0.6</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp --> 
    <dependency> 
     <groupId>commons-dbcp</groupId> 
     <artifactId>commons-dbcp</artifactId> 
     <version>1.4</version> 
    </dependency> 

    <!-- https://mvnrepository.com/artifact/commons-pool/commons-pool --> 
    <dependency> 
     <groupId>commons-pool</groupId> 
     <artifactId>commons-pool</artifactId> 
     <version>1.6</version> 
    </dependency> 
    <dependency> 
     <groupId>com.opencsv</groupId> 
     <artifactId>opencsv</artifactId> 
     <version>3.7</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io --> 
    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-io</artifactId> 
     <version>1.3.2</version> 
    </dependency> 
    <!-- https://mvnrepository.com/artifact/com.google.guava/guava --> 
    <dependency> 
     <groupId>com.google.guava</groupId> 
     <artifactId>guava</artifactId> 
     <version>19.0</version> 
    </dependency> 


    <!-- https://mvnrepository.com/artifact/commons-collections/commons-collections --> 
    <dependency> 
     <groupId>commons-collections</groupId> 
     <artifactId>commons-collections</artifactId> 
     <version>3.0</version> 
    </dependency> 


    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-csv</artifactId> 
     <version>1.3</version> 
    </dependency> 

    <dependency> 
     <groupId>net.lingala.zip4j</groupId> 
     <artifactId>zip4j</artifactId> 
     <version>1.3.2</version> 
    </dependency> 
</dependencies> 

<build> 
<finalName>gt20047</finalName> 
    <sourceDirectory>src</sourceDirectory> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.1</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.3</version> 
      <configuration> 

       <archive> 
       <manifest> 
        <!-- Jar file entry point --> 
        <mainClass>org.postprocessor.dao.DaoMain</mainClass> 
       </manifest> 
       </archive> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

ne suis pas en mesure de savoir où est le problème, mon fichier jar n'a pas ce dossier de configuration enter image description here

DaoMain.java

package org.postprocessor.dao; 

import java.io.File; 

import org.postprocessor.util.FileZipper; 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 

public class DaoMain { 
    public static void main(String[] args) { 
     ApplicationContext ctx= new ClassPathXmlApplicationContext("classpath:/org/postprocessor/config/dataSupport.xml"); 
     DaoImpl daoImpl=null; 
     FileZipper fileZipper=null; 
     try{ 
      daoImpl= ctx.getBean("daoImpl",DaoImpl.class); 
      fileZipper= ctx.getBean("fileZipper",FileZipper.class); 
      daoImpl.startProcess(); 
      fileZipper.zipFile(new File("").getAbsolutePath()+"/output"); 
     } 
     catch(Exception e){ 
      e.printStackTrace(); 
     } 
     finally{ 
      ((ClassPathXmlApplicationContext) ctx).close(); 
     } 
     } 
    } 
  • Comment résoudre ce problème?
+0

stacktraces Post comme texte non comme image – Jens

+0

Où se trouve 'dataSupport.xml' dans votre pot? – Jens

+0

la construction n'inclut pas ce fichier dataSupport.xml, c'est y J'ai l'erreur – sailaja

Répondre

0

Vos fichiers XML ne sont pas bien formés.

Bien que je ne sais pas si c'est le problème, il peut être la cause de la raison pour laquelle votre projet ne prend pas les fichiers correctement en premier lieu.

Votre balise <beans> ne possède pas de balise de fermeture. Essayez de mettre </beans> à la fin du fichier.

En outre, votre fichier pom.xml a le même problème. Le <project> n'est pas fermé. Essayez de mettre </project> à la fin du fichier.

+0

les deux fichiers sont corrects, mais manqué coller ici, des excuses pour l'erreur idiote ... essayé le problème est incapable de construire le fichier jar avec ce fichier beans, et donc obtenir l'erreur ... mais je peux exécuter l'application en utilisant Application Java en éclipse mais j'ai besoin du fichier jar pour l'ajouter dans le fichier batch ... pour l'exécuter – sailaja

10

On dirait que le principal problème est à cette ligne:

new ClassPathXmlApplicationContext("classpath:/org/postprocessor/config/dataSupport.xml"); 

Vous essayez de construire le contexte de classpath. Vous devez donc localiser votre fichier de configuration accessible depuis un classpath de votre projet. Vous utilisez Maven pour construire votre projet.Maven a défini la structure de projet pour sources de code et pour ressources:

/src/main/java 
/src/main/resorces 

Vous pouvez trouver plus d'ici: Introduction to the Standard Directory Layout

Si vous voulez rendre votre fichier accessible à partir classpath vous doit le mettre exactement sous - resources/ dossier:

enter image description here

Maintenant, vous main() sera, quelque chose comme:

public static void main(String[] args) { 
    ApplicationContext ctx= new ClassPathXmlApplicationContext("classpath:config/dataSupport.xml"); 
    Object dataSource = ctx.getBean("userRepo"); 
    System.out.println(dataSource.getClass().getName()); 
    // use your beans here 

Je créé juste haricot démo. Et voici la sortie:

2017-03-20 15:22:40 INFO ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.Cla[email protected]: startup date [Mon Mar 20 15:22:40 EET 2017]; root of context hierarchy 
2017-03-20 15:22:40 INFO XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [config/dataSupport.xml] 
demo.repository.UserRepository 

BTW vous pouvez utiliser try with resources pour le contexte de l'application:

try(ClassPathXmlApplicationContext ctx = 
    new ClassPathXmlApplicationContext("classpath:config/dataSupport.xml")) { 
    // use your beans here 
} 

Ressources supplémentaires:

0

Je pense que ce qui suit devrait fonctionner:

ApplicationContext ctx= new ClassPathXmlApplicationContext("org/postprocessor/config/dataSupport.xml");

Vous n'avez pas besoin de spécifier « classpath » puisque vous utilisez déjà ClassPathXmlApplicationContext, et vous avez slash supplémentaire au début.

0

mouvement:

src/org/postprocessor/config/dataSupport.xml

à:

src/main/resources/org/postprocessor/config/dataSupport.xml

+0

Cela ne fournit pas de réponse à la question. Pour critiquer ou demander des éclaircissements à un auteur, laissez un commentaire sous son article. - [À revoir] (/ review/low-quality-posts/15641594) – DimaSan

+0

OP a demandé: "Comment résoudre ce problème?" à laquelle la réponse est: "déplacez votre fichier de configuration dans l'emplacement correct". Y at-il quelque chose de pas clair à ce sujet? – ninj

+0

Vous pouvez améliorer la qualité de votre message en ajoutant quelques explications. Rappelez-vous que vous répondez à la question pour les lecteurs dans le futur, et que ces personnes pourraient ne pas connaître les raisons de votre suggestion de code. – DimaSan

0

Par défaut maven-plugin-compilateur ne comprend pas les fichiers non-java. qui vous a laissé deux options.
1. déplacer vos fichiers de ressources (.properties, .xml, etc.) à "src/main/resources" (RECOMMANDÉ.)
2. utiliser le plugin de ressources Maven

<plugin> 
    <artifactId>maven-resources-plugin</artifactId> 
    <version>2.6</version> 
    <executions> 
     <execution> 
     <id>copy-resources</id> 
     <phase>validate</phase> 
     <goals> 
      <goal>copy-resources</goal> 
     </goals> 
     <configuration> 
      <outputDirectory>${basedir}/path/where/you/want</outputDirectory> 
      <resources> 
      <resource> 
       <directory>${basedir}</directory> 
       <includes> 
        <include>**/*.xml</include> 
       </includes> 
      </resource> 
      </resources> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin>