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 Java Discussion :

[Spring Batch] 1ers pas : nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreExce


Sujet :

Spring Java

  1. #1
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2007
    Messages
    167
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 167
    Points : 112
    Points
    112
    Par défaut [Spring Batch] 1ers pas : nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreExce
    Bonjour,

    je fais mes premiers pas avec spring batch. J'essaye dans un premier temps de faire un simple déchargement d'une table postgresql vers un fichier .csv.

    J'ai la configuration suivante :

    spring-context.xml :

    Code : 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
    <?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:cache="http://www.springframework.org/schema/cache"
           xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:cxf="http://cxf.apache.org/core"
           xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:security="http://www.springframework.org/schema/security"
           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/context http://www.springframework.org/schema/task/spring-context-3.0.xsd
                               http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
                               http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
                               http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
    						   http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
                               http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                               http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
     
            <!-- Contient le transactionManager, entityManagerFactory... -->
    	<import resource="classpath:commonSpringContext.xml" />
     
        <!-- Basic Configurations -->
        <cache:annotation-driven />
        <context:annotation-config/>
     
        <context:component-scan base-package="fr.xxxxx.xxxxx.*"/>
     
        <import resource="spring-jpa-dev.xml"/>
     
     
    	<!-- Define a resourceless transaction manager for the in-memory job repository -->
        <bean id="repositoryTransactionManager"
        class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
     
    	<!-- Define in-memory job repository  -->
        <bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"/>
     
        <!-- Define the synchronous job launcher -->
        <bean id="syncJobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
            <property name="jobRepository" ref="jobRepository" />
        </bean>
     
        <!-- SpringBatch -->
    	<import resource="spring-batch-dev.xml"/>
    </beans>
    spring-jpa-dev.xml :

    Code : 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
    <?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:jee="http://www.springframework.org/schema/jee"
           xmlns:jpa="http://www.springframework.org/schema/data/jpa"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           					   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                               http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
                               http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd">
     
     	<jee:jndi-lookup id="dataSourceMetier" jndi-name="xxxxx" />
     
        <!-- Spring Data -->
        <jpa:repositories base-package="fr.xxxxx.xxxxx.core.dao" factory-class="fr.xxxxx.xxx.commons.dao.CustomJpaRepositoryFactoryBean"
                          entity-manager-factory-ref="entityManagerFactory"
                          transaction-manager-ref="transactionManager"/>
     
    </beans>
    spring-batch-dev.xml :

    Code : 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
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:batch="http://www.springframework.org/schema/batch"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/batch
                        http://www.springframework.org/schema/batch/spring-batch-3.0.xsd
                        http://www.springframework.org/schema/util
                        http://www.springframework.org/schema/util/spring-util-3.0.xsd">
     
        <bean id="statSessionItemReader" class="org.springframework.batch.item.database.JpaPagingItemReader">
    	    <property name="entityManagerFactory" ref="entityManagerFactory" />
    	    <property name="queryString" value="Select ss from StatSession ss" />
       </bean>
     
        <bean id="statSessionProcessor" class="fr.xxxxx.xxxxx.batch.processors.StatSessionProcessor" />
     
        <bean id="statsItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
            <property name="resource" value="file:#{jobParameters['output.file']}" />
     
            <property name="lineAggregator">
                <bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
                    <property name="delimiter" value=";" />
                </bean>
            </property>
        </bean>
     
        <!-- Test Job definition -->
        <batch:job id="TestJob" incrementer="jobParametersIncrementer">
            <batch:step id="Test_step1">
                <batch:tasklet>
                    <batch:chunk reader="statSessionItemReader" writer="statsItemWriter" commit-interval="10" />
                </batch:tasklet>
            </batch:step>
        </batch:job>
     
        <!-- ================================================== -->
        <!-- Common Beans that are used in multiple scenarios -->
        <!-- ================================================== -->
     
        <!-- Increments the Job ID -->
        <bean id="jobParametersIncrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer" />
     
    </beans>

    main pour tester :

    Code : 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
    import org.springframework.batch.core.Job;
    import org.springframework.batch.core.JobExecution;
    import org.springframework.batch.core.JobExecutionException;
    import org.springframework.batch.core.JobParameters;
    import org.springframework.batch.core.JobParametersBuilder;
    import org.springframework.batch.core.launch.JobLauncher;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
     
    public class Batch {
     
    	public static void main (String [] args) throws Exception {
    		 ClassPathXmlApplicationContext cpt = new ClassPathXmlApplicationContext("spring-context.xml");
    		 cpt.start();
     
    		 JobLauncher jobLauncher = (JobLauncher) cpt.getBean("syncJobLauncher");
    		 Job job = (Job) cpt.getBean("TestJob");
    		 JobParameters parameter = new JobParametersBuilder().addString("output.file", "C:/Temp/resultat.csv").toJobParameters();
     
    	     try {
    	         JobExecution execution = jobLauncher.run(job, parameter);
    	         System.out.println("Job Exit Status : "+ execution.getStatus());
    	     } catch (JobExecutionException e) {
    	         System.out.println("Job ExamResult failed");
    	         e.printStackTrace();
    	     }
    	}
     
    }
    Lorsque je run as Java Application :

    Code : 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
    Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [spring-batch-dev.xml]
    Offending resource: class path resource [spring.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 42 in XML document from class path resource [spring-batch-dev.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 42; columnNumber: 68; cvc-complex-type.2.4.c : Le caractère générique concordant est strict, mais aucune déclaration ne peut être trouvée pour l'élément 'batch:job'.
    	at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
    	at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
    	at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:282)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:207)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:192)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
    	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:130)
    	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    	at Batch.main(Batch.java:15)
    Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 42 in XML document from class path resource [spring-batch-dev.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 42; columnNumber: 68; cvc-complex-type.2.4.c : Le caractère générique concordant est strict, mais aucune déclaration ne peut être trouvée pour l'élément 'batch:job'.
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:266)
    	... 20 more
    Caused by: org.xml.sax.SAXParseException; lineNumber: 42; columnNumber: 68; cvc-complex-type.2.4.c : Le caractère générique concordant est strict, mais aucune déclaration ne peut être trouvée pour l'élément 'batch:job'.
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:449)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3228)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1908)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:737)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:376)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2715)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
    	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
    	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:240)
    	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300)
    	at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
    	... 23 more
    Je ne vois pas ce qui ne convient pas dans mon <batch:job> ...

    Merci d'avance !

  2. #2
    Expert confirmé
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 936
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 936
    Points : 4 356
    Points
    4 356
    Par défaut
    et
    tout simplement ?

  3. #3
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2007
    Messages
    167
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 167
    Points : 112
    Points
    112
    Par défaut
    Erreur suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Offending resource: class path resource [spring.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 42 in XML document from class path resource [spring-batch-dev.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 42; columnNumber: 62; cvc-complex-type.2.4.a : Contenu non valide trouvé à partir de l'élément 'job'. L'une des valeurs '{"http://www.springframework.org/schema/beans":import, "http://www.springframework.org/schema/beans":alias, "http://www.springframework.org/schema/beans":bean, WC[##other:"http://www.springframework.org/schema/beans"]}' est attendue.

  4. #4
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Bonjour,

    Vérifie bien les schémas que tu as dans ton jar (spring-batch-core-*.*.*.jar).

    A+.

  5. #5
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2007
    Messages
    167
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 167
    Points : 112
    Points
    112
    Par défaut
    Citation Envoyé par andry.aime Voir le message
    Bonjour,
    Vérifie bien les schémas que tu as dans ton jar (spring-batch-core-*.*.*.jar).
    A+.
    ... ok ! Ça passe mieux avec ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    http://www.springframework.org/schema/batch
    http://www.springframework.org/schem...-batch-2.2.xsd
    Ça bloque plus loin mais au moins j'avance ! Merci !

  6. #6
    Expert confirmé
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 936
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 936
    Points : 4 356
    Points
    4 356
    Par défaut
    spring-batch 2.2.x est compatible avec spring 3.2 : ce qui vous permet d'utiliser le schema de ce dernier, avec notamment l'avantage de bénéficier de <beans profile=... >

Discussions similaires

  1. [JSF] org.springframework beans factory BeanCreationException
    Par yLaplace dans le forum Spring Web
    Réponses: 1
    Dernier message: 09/12/2010, 14h48
  2. Réponses: 0
    Dernier message: 29/04/2010, 14h50
  3. Réponses: 2
    Dernier message: 22/04/2009, 14h06
  4. Réponses: 7
    Dernier message: 19/01/2009, 08h39
  5. Réponses: 2
    Dernier message: 31/05/2007, 12h19

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