Click here to Skip to main content
15,921,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to store some state, I receive in the processor, for each of the StepExecutions separately. For this purpose I created a step-scoped bean, which I try to inject:

@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SomeConfiguration
// here go the job definition with one step, which has a reader, writer and processor
    public SomeProcessor processingStep(StateService s)
        var processor = new SomeProcessor();
        return processor;

    // StateService is an empty class
    @Scope(value = "step", proxyMode = ScopedProxyMode.NO)
    public StateService stateService()
        return new StateService();

Whatever I do, I get either NoSuchBeanDefinitionException or ClassCastException, since Spring Batch doesn't get along with its proxies. How to use @StepScope in Spring Batch? There is literally no documentation about how these @StepScope and @JobScope work, just an incomplete example here (only a declaration example, no clues of how to use step-scoped bean).

What I have tried:

Calling stateService bean directly:

Changing ScopedProxyMode to all possible values;

Injecting stateService directly into processor:
public class SomeProcessor implements ItemProcessor<EFrom, ETo>
    // ...
    private StateService stService;
    // ...

Removing @EnableBatchProcessing annotation from configuration file.
Updated 12-Oct-22 7:37am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900