Safina
Feb 6, 2022

Hey Nyamath. You can find a sample springbatch project which illustartes the proper usage of step scoped beans here https://github.com/SafinaAh/SpringBatchExamples.

This example job has two steps both of which use the same,reader and writer. However as they are step scoped you the instances used by step 1 and step 2 are not the same.

You can confirm the same by running this job once and it will print out the hashcode of the reader,writer and processor instances.

As for why you might have encountered this exception I cannot really say without looking at your code first but I am listing the most common causes here

Missing noargs constructor in the step scoped bean class-- If the bean is autowired or used by another autowired bean spring will attempt to create proxies for the step scoped bean which require a no args constructor

Missing @EnableBatchProcessing annotation in your configuration class

Safina
Safina

Written by Safina

Smart. Strong. Silly. First I drink coffee. Then I do things. Hodophile. Adrenaline junkie :)

Responses (1)