2013-12-08 117 views
0

在Spring批處理中,在ItemReader或ItemProcessor返回它的item對象後,框架將該項放入一個ArrayList以傳遞給ItemWriter。Spring ID生成的項目列表的Bean ID

我需要訪問ItemProcessor中項目的ArrayList。我需要的核心功能是訪問Arraylist,而ItemReader/ItemProcessor正在處理它的塊。

我的想法是使用了ApplicationContextAware ItemProcessor中,讓我做以下電話:

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

但豆未命名的項目。

你知道我如何訪問該ArrayList或Bean的名稱,以便我可以在那裏強制它嗎?

+1

這個要求的目的是什麼?你試圖對物品清單做什麼? –

回答

2

使用以下彈簧批次註釋(因爲彈簧批次可用2.0)

@BeforeWrite
標記的方法的項被傳遞到一個 ItemWriter
預期簽名之前調用:無效beforeWrite(列表 項目)上的作家

方法標有此註釋之前 你寫方法將執行每一個塊。

+0

這會在ItemProcessor中工作嗎?要求是訪問ItemProcessor中的項目的ArrayList。 – cyotee

+0

這是相同的數組列表。 但是,如果你喜歡在ItemProcessor級別使用這個,使用 @ BeforeProcess/@ AfterProcess 但是,這將只能訪問一個項目 –

+0

就是這樣,我需要在ItemProcessor中獲取ArrayList。 – cyotee