Search code examples
spring-bootspring-dataspring-batch

AbstractItemCountingItemStreamItemReader throws Exception that makes no sense


I implement the following methods on the AbstractItemCountingItemStreamItemReader as follows:

      @Override 
     protected Object doRead() {
     Product product = productIteratorItemReader.read();
       if (product == null) {
        readNextProducts();
        product = productIteratorItemReader.read();
      }
       return product;
     }

      @Override
      protected void doOpen() {
         initialProductIterator(); // Initialize the iterator to be able read from it
      }

And finally

  public void readNextProducts() {
    if (productsIdListIterator.hasNext()) {
        List<Long> productIds = productsIdListIterator.next();
        List<Product> products = 
        productService.queryForProducts(departmentIds);
        productIteratorItemReader = new IteratorItemReader<>(products);
    }
}

Unfortunately it is hard to find any example on how to use it. This is my simple implementation. However when I start my job I get the exception below which makes little sense to me. I have no idea why I need to set a Name and I don't know how to do it. Any help will be very much appreciated. Thanks in advance

java.lang.IllegalArgumentException: Name must be assigned for the sake of defining the execution context keys prefix.


Solution

  • I use super.setName(NAME) in my constructor