I need to store some state, I receive in the processor, for each of the
StepExecution
s separately. For this purpose I created a step-scoped bean, which I try to inject:
@Slf4j
@Configuration
@EnableScheduling
@EnableBatchProcessing
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SomeConfiguration
{
@StepScope
@Bean
public SomeProcessor processingStep(StateService s)
{
var processor = new SomeProcessor();
processor.setStService(s);
return processor;
}
@Scope(value = "step", proxyMode = ScopedProxyMode.NO)
@Bean
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:
processor.setStService(stateService());
Changing
ScopedProxyMode
to all possible values;
Injecting stateService directly into processor:
public class SomeProcessor implements ItemProcessor<EFrom, ETo>
{
@Autowired
private StateService stService;
}
Removing
@EnableBatchProcessing
annotation from configuration file.