简体   繁体   中英

Spring-Batch: Define a parent job with parameters

I am using spring-batch to copy data from one datasource into another. I have multiple xml files with the defintions of the necessary steps and jobs. They are all pretty similar with a lot of duplicate "code". The only differences are ususally the SQL that selects data from the first datasource and the name of the table where the data is inserted in the second datasource.

I would like to create a parent job that consists of the steps and jobs to copy the data and only takes the SQL and the name of the target table as a parameter. I know, i can set a parent job with the 'parent' attribute:

<batch:job id="copyDataJob1" parent="AbstractCopyJob">
    ...
</batch>

But how can I pass and use these parameters in the definition of the parent job?

Steps within a job definition are not inherited (we wouldn't know where to put them in the new flow) so what you're attempting isn't 100% possible. What you can do, however, is define a parent step (or steps) that you define the appropriate pieces for. From there, each job definition you create, would be just a list of steps extending the parent.

That being said, if the SQL in a reader is all that changes from run to run, why not just have a single job definition, define your reader as step scoped and use a job parameter to pass in the SQL?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM