Can Spring Batch jobs be configured at run time with dynamic steps?
Solution 1
the job configuration itself is set before the job runs, but it is possible to create a flexible job configuration with conditional flows
you can't just change the job configuration while the job runs, but between jobs its easy to replace the configuration
Solution 2
Addon for Michael answer:
Do you want to create a flow from beginning to end completely dynamically or you want to have some dynamics at certain point?
- As Spring Batch instantiates jobs (will all internals) from XML configuration, that means all necessary beans have setters/getters and you can create the Job from empty page. This is long and bug-prone way (you need to create
FlowJob
as inJobParserJobFactoryBean
goes, thenSimpleFlow
thenStepState
thenTaskletStep
as inSimpleStepFactoryBean
and bind them together). - I think the alternative to XML flows could be your coded logic. For String Batch it will look as one step, but with custom implementation and subflow. See
<tasklet ref="myCleverTasklet" />
example in Example Tasklet Implementation.
ltfishie
Updated on June 05, 2022Comments
-
ltfishie almost 2 years
I am looking at Spring Batch 2.0 to implement a pipeline process. The process is listening to some event, and needs to perform a set of transformation steps base on the event type and its content.
Spring batch seem to be a great fit. However, going through the documentation, every example have them job and its steps configured in xml. Does the framework support creating jobs during run-time and configuring the steps dynamically?