0
votes

In Spring Batch, after a ItemReader or ItemProcessor returns it's item object, the framework puts that item into an ArrayList to be passed to the ItemWriter.

I need to gain access to that ArrayList of items in an ItemProcessor. The core functionality I need is to access the Arraylist while the ItemReader/ItemProcessor is processing it's chunk.

My thought was to use an ApplicationContextAware ItemProcessor, allowing me to make the call below:

ArrayList<? extends Item> items = context.getBean("items", ArrayList.class)

But the bean is not named items.

Do you know how I can gain access to that ArrayList, or the name of the Bean so I can force it in there?

1
What is the purpose of this requirement? What are you attempting to do with the list of items? - Michael Minella

1 Answers

2
votes

Use the following spring batch annotation (available since spring batch 2.0)

@BeforeWrite
Marks a method to be called before an item is passed to an ItemWriter
Expected signature: void beforeWrite(List items)

Method on your writer marked with this annotation will be execute for every chunk before your write method.