Running job multiple times with different resources
I'm having a problem of needing to run a job multiple times with different resources for the itemReader, but i'm not sure how to implement this dynamic attribution of the files (which is a list of the .xml files under a certain directory).
Each run of a job must focus on one resource, that is, the all steps must focus on the same resource.
The structure of the XML has one only header and several Invoices.
Code:
<Header>...</Header>
<Invoice>...</Invoice>
<Invoice>...</Invoice>
<Invoice>...</Invoice>
and the context is as follows:
Code:
<batch:job id="SPIntegracao">
<batch:step id="SPIntegracaoCriaEstadoHeader" next="SPIntegracaoStep1">
<batch:tasklet>
<batch:chunk reader="itemReader" processor="SPTHeaderProcessor"
writer="ZeroWriter" commit-interval="${pagingDefault.commitInterval}" />
</batch:tasklet>
</batch:step>
<batch:step id="SPIntegracaoStep1" next="SPTIntegracaoFinalStep">
<batch:tasklet>
<batch:chunk reader="itemReader2" processor="SPTIntegracaoProcessor"
writer="SPTIntegracaoWriter" commit-interval="${pagingDefault.commitInterval}" />
</batch:tasklet>
</batch:step>
<batch:step id="SPTIntegracaoFinalStep">
<batch:tasklet ref="jobEndTasklet"></batch:tasklet>
</batch:step>
</batch:job>
<bean id="itemReader" class="org.springframework.batch.item.xml.StaxEventItemReader">
<property name="fragmentRootElementName" value="Header" />
<property name="resource" value="file:example2.xml" />
<property name="unmarshaller" ref="tradeMarshaller" />
</bean>
<bean id="itemReader2" class="org.springframework.batch.item.xml.StaxEventItemReader">
<property name="fragmentRootElementName" value="Invoice" />
<property name="resource" value="file:example2.xml" />
<property name="unmarshaller" ref="tradeMarshaller2" />
</bean>
Is there anyway to on one batch execution run the job multiple times with different resources for each job execution?
I'm trying to keep all the logic to the Springframework.
Any directions or workarounds are appreciated.
Thanks!