Calling another job from a processor in spring batch

谁都会走 提交于 2019-12-04 17:53:32
Haim Raman

Consider wrapping the exiting job with a second job and using the batch:job element with job-parameters-extractor within the batch:step element.

The external job should include your logic of required file list with a decider. batch:job will call your exiting job and job-parameters-extractor using the org.springframework.batch.core.step.job.JobParametersExtractor interface that will copy the required file path to the internal job.

Look at the following answer where I used the elements above.

Logically your job will look like

<batch:job id="jobWrapper" incrementer="runIdIncrementer" >
        <batch:step id="createFileList" next="callInternalJob">
            <batch:tasklet ref="fileterRequiredFilesTasklet"/>
        </batch:step>
        <batch:step id="callInternalJob" next="hasMoreFileDecision">
            <batch:job ref="yourJob" job-launcher="jobLauncher"
                job-parameters-extractor="extractCurrentFileParam" />
        </batch:step>
        <batch:decision id="hasMoreFileDecision" decider="hasMoreFileDecider">
            <batch:next on="NEXTFILE" to="callInternalJob" />
            <batch:end  on="COMPLETED" exit-code="COMPLETED" />
        </batch:decision>
    </batch:job>  

fileterRequiredFilesTasklet - create the list of required files and store it in the Job Execution context callInternalJob - Call your exiting job and passing the current file to process via the callInternalJob hasMoreFileDecider - will loop over the list of files created by fileterRequiredFilesTasklet util all were processed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!