I have a requirement where I need to process files based on the rest call in which I get the name of the file, I am adding it to the job parameter and using it while creati
A spring batch StepScope
object is one which is unique to a specific step and not a singleton. As you probably know, the default bean scope in Spring is a singleton. But by specifying a spring batch component being StepScope
means that Spring Batch will use the spring container to instantiate a new instance of that component for each step execution.
This is often useful for doing parameter late binding where a parameter may be specified either at the StepContext
or the JobExecutionContext
level and needs to be substituted for a placeholder, much like your example with the filename requirement.
Another useful reason to use StepScope
is when you decide to reuse the same component in parallel steps. If the component manages any internal state, its important that it be StepScope
based so that one thread does not impair the state managed by another thread (e.g, each thread of a given step has its own instance of the StepScope
component).