I have a Spring Batch project with a simple custom reader and writer. When i run the code i end up with an endeless loop printing the first item "item 1". What am i doing wrong?
Here is my code:
Reader.java
public class Reader implements ItemReader<SimpleItem> {
public SimpleItem read() throws Exception, UnexpectedInputException, ParseException {
if (getIterator().hasNext()) {
return getIterator().next();
}
return null;
}
public Iterator<SimpleItem> getIterator() {
List<SimpleItem> list = new ArrayList();
list.add(new SimpleItem("item 1"));
list.add(new SimpleItem("item 2"));
return list.iterator();
}
}
Writer.java
public class Writer implements ItemWriter<SimpleItem> {
@Override
public void write(List<? extends SimpleItem> list) throws Exception {
for(SimpleItem item : list) {
System.out.println(item.getName()); // this prints item 1 endelessly
}
}
}