Welcome to the new Spring.io forums!
If this is your first visit, be sure to check out the
by clicking the link above, and for security reasons, use the
forgot password link to reset your password..
You may have to register before you can post: click the register
link above to proceed. To start viewing messages, select the forum that you want to visit
from the selection below.
I have asked similar question before and here is what I understood, wish it can help:
Normally, tasklet is singleton by default. Therefore, if the tasklet's logic is stateless, it will run well.
However, if you want to have a stateful, or want to be StepContextAware, you may make the scope of the tasklet being "step" (you should register the scope first, refer to the unit test), and put <aop:scoped-proxy/> in the tasklet's bean config in app context. It should make your tasklet instantiated for every new step.
When using steps, lots of very stateful resources are generally created. For example, if reading from the database you may open a cursor that stays open for the life of the batch job. This should be closed as soon as the step finishes, which is why we have step scope, to ensure resources are free. So, in theory, you could make your steps 'prototype scoped', but that doesn't necessarily guarantee that the resources created will be released without using something like step scope or closing the application context.
As a side note, there's an issue to move the responsibilities of step scope to the step itself, but the overall effect is the same: