Announcement Announcement Module
Collapse
No announcement yet.
Problem running partitionJdbcJob Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem running partitionJdbcJob

    Hello,
    I am trying to run the partitionJdbcJob, to try to parallelize a batch in several thread. My configuration file is the following :

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:util="http://www.springframework.org/schema/util" xmlns:batch="http://www.springframework.org/schema/batch"
    	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
    		http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
    
    	<!-- CREATION DES BEANS DE PARAMETRAGE DU BATCH -->
    
    	<bean id="transactionManager"
    		class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"
    		p:dataSource-ref="dataSource" />
    
    	<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean" p:transactionManager-ref="transactionManager"/>
    
    	<bean id="jobLauncher"
    		class="org.springframework.batch.core.launch.support.SimpleJobLauncher"
    		p:jobRepository-ref="jobRepository"  />
    
    	<!-- CREATION DU BATCH A PROPREMENT PARLER -->
    
    	<batch:job id="BouyguesJob" job-repository="jobRepository">
    		<batch:step id="step">
    			<batch:partition step="stepLecture" partitioner="partitioner">
    				<batch:handler grid-size="2" task-executor="taskExecutor" />
    			</batch:partition>
    		</batch:step>
    	</batch:job>
    
    	<!-- STEP LECTURE BDD -->
    	<batch:step id="stepLecture">
    		<batch:tasklet transaction-manager="transactionManager">
    			<batch:chunk reader="itemReader" processor="itemProcessorFiltre"
    				writer="itemWriterFiltreCastor" commit-interval="100"></batch:chunk>
    		</batch:tasklet>
    	</batch:step>
    
    	<bean id="itemReader" scope="step" autowire-candidate="false"
    		parent="itemReaderParent">
    		<property name="sql">
    			<value> 
    		<![CDATA[ 
    			select * from clients where ID >= ? and ID <= ? 
    		]]>
    			</value>
    		</property>
    		<property name="preparedStatementSetter">
    			<bean
    				class="org.springframework.batch.core.resource.ListPreparedStatementSetter">
    				<property name="parameters">
    					<list>
    						<value>#{stepExecutionContext[minValue]}</value>
    						<value>#{stepExecutionContext[maxValue]}</value>
    					</list>
    				</property>
    			</bean>
    		</property>
    	</bean>
    
    	<bean id="itemReaderParent"
    		class="org.springframework.batch.item.database.JdbcCursorItemReader"
    		abstract="true">
    		<property name="dataSource" ref="dataSourceClients" />
    		<property name="rowMapper">
    			<bean class="ressourcesBouygues.RowMapperClientSimple" />
    		</property>
    	</bean>
    
    
    	<bean id="itemProcessorFiltre" class="stepDeux.ProcessorClientsResilies" />
    
    
    	<bean id="itemWriterFiltreCastor" class="org.springframework.batch.item.xml.StaxEventItemWriter"
    		scope="step">
    		<property name="resource" ref="outputResource" />
    		<property name="rootTagName" value="listeClients" />
    		<property name="marshaller" ref="clientMarshallerCastor" />
    		<property name="saveState" value="false" />
    		<property name="version" value="1.0" />
    	</bean>
    
    	<bean id="outputResource" class="org.springframework.core.io.FileSystemResource">
    		<constructor-arg
    			value="./src/ressourcesBouygues/listeClientsRetournesBDD.xml" />
    	</bean>
    
    	<bean id="clientMarshallerCastor" class="org.springframework.oxm.castor.CastorMarshaller">
    		<property name="mappingLocation"
    			value="file:./src/ressourcesBouygues/mappingSimple.xml" />
    	</bean>
    
    
    	<!-- DONNEES DE PARALLELISATION -->
    	<bean id="partitioner" class="ressourcesBouygues.PartitionneurBDD">
    		<property name="dataSource" ref="dataSourceClients" />
    		<property name="table" value="clients" />
    		<property name="column" value="ID" />
    	</bean>
    
    	<bean id="taskExecutor" class="org.springframework.core.task.SyncTaskExecutor" />
    
    	<!-- BASE DE DONNEES -->
    	<bean id="dataSource"
    		class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
    		<property name="url" value="jdbc:mysql://localhost/batch" />
    		<property name="username" value="root" />
    		<property name="password" value="" />
    		<property name="suppressClose" value="true" />
    	</bean>
    
    	<bean id="dataSourceClients"
    		class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
    		<property name="url" value="jdbc:mysql://localhost/donnees_bouygues" />
    		<property name="username" value="root" />
    		<property name="password" value="" />
    		<property name="suppressClose" value="true" />
    	</bean>
    
    </beans>
    However, when running the batch, this error appears :
    Code:
    Lancement batch
    Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: The 'job-repository' attribute may exist on an <batch:tasklet/> element.
    Offending resource: class path resource [ressourcesBouygues/applicationContextStep2AvecParallelisationBDD.xml]
    	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:72)
    	at org.springframework.batch.core.configuration.xml.AbstractStepParser.resolveJobRepositoryRef(AbstractStepParser.java:176)
    	at org.springframework.batch.core.configuration.xml.AbstractStepParser.setUpBeanDefinitionForTaskletStep(AbstractStepParser.java:151)
    	at org.springframework.batch.core.configuration.xml.AbstractStepParser.parseTasklet(AbstractStepParser.java:133)
    	at org.springframework.batch.core.configuration.xml.AbstractStepParser.parseStep(AbstractStepParser.java:85)
    	at org.springframework.batch.core.configuration.xml.StandaloneStepParser.parse(StandaloneStepParser.java:40)
    	at org.springframework.batch.core.configuration.xml.TopLevelStepParser.parseInternal(TopLevelStepParser.java:39)
    	at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:56)
    	at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
    	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1297)
    	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:80)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
    	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    	at batchBouygues.AppBouygues.main(AppBouygues.java:28)
    Could you please help me ? I don't see where it can come from.
    Thanks in advance !

  • #2
    Not sure I understand the actual issue but if your jobRepository is named "jobRepository" and you only have one in your context, you don't need to specify it at all. What happens if you remove the job-repository attribute on your batch?

    Comment


    • #3
      Stephane is correct. There's no need for the jobRepository to be explicity specified, but it should be injected into the step automatically if it is present in the job.

      The weird thing is: I can't find any reference to a method setUpBeanDefinitionForTaskletStep in AbstractStepParser in any version of Spring Batch, so your stack trace is very confusing. What version are you using? Where did you get the jar files?

      Comment

      Working...
      X