org.springframework.batch.item.ItemStreamException: Failed to initialize the reader

Spring JIRA | Oliver Theissen | 8 years ago
  1. 0

    Steps to reproduce the bug -------------------------- 1.) create a working directory 2.) unzip attachment "spring.batch.bug.zip" in this working directory. 3.) compile (assuming environment set up as specified) 7.) run the main method in class ItemReaderTest Actual behavior --------------- Output on the console: Exception in thread "main" org.springframework.batch.item.ItemStreamException: Failed to initialize the reader at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:111) at batch.bug.ItemReaderTest.testItemReader(ItemReaderTest.java:49) at batch.bug.ItemReaderTest.main(ItemReaderTest.java:34) Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): class path resource [employeeResource] at org.springframework.batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:245) at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:108) ... 2 more Expected behavior ----------------- Output on the console: [[name=joel,firstName=miller], [name=greg,firstName=taylor], [name=michael,firstName=carpenter]] Remark ------ If I insert the following workaround into class ItemReaderTest I get the expected result: ... public void testItemReader() throws UnexpectedInputException, ParseException, Exception { List<Employee> employeeList = new ArrayList<Employee>(); Employee current; // BEGIN workaround --------------------------------------------------- Resource resource = (Resource) ctx.getBean("employeeResource"); itemReader.setResource(resource); // END workaround ----------------------------------------------------- itemReader.open(new ExecutionContext()); // fails, if resource is not set explicitly! ... Seems that dependency injection for the resource property of a FlatFileItemReader (or one of it's superclasses) does not work correctly. In practice, this workaround is useless because a you cannot access the ItemReader injected into a StepExecution before the open(...) method is called on an ItemReader. Thus there is not place to invoke setResource(...) on the ItemReader before it is actually used.

    Spring JIRA | 8 years ago | Oliver Theissen
    org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
  2. 0

    Steps to reproduce the bug -------------------------- 1.) create a working directory 2.) unzip attachment "spring.batch.bug.zip" in this working directory. 3.) compile (assuming environment set up as specified) 7.) run the main method in class ItemReaderTest Actual behavior --------------- Output on the console: Exception in thread "main" org.springframework.batch.item.ItemStreamException: Failed to initialize the reader at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:111) at batch.bug.ItemReaderTest.testItemReader(ItemReaderTest.java:49) at batch.bug.ItemReaderTest.main(ItemReaderTest.java:34) Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): class path resource [employeeResource] at org.springframework.batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:245) at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:108) ... 2 more Expected behavior ----------------- Output on the console: [[name=joel,firstName=miller], [name=greg,firstName=taylor], [name=michael,firstName=carpenter]] Remark ------ If I insert the following workaround into class ItemReaderTest I get the expected result: ... public void testItemReader() throws UnexpectedInputException, ParseException, Exception { List<Employee> employeeList = new ArrayList<Employee>(); Employee current; // BEGIN workaround --------------------------------------------------- Resource resource = (Resource) ctx.getBean("employeeResource"); itemReader.setResource(resource); // END workaround ----------------------------------------------------- itemReader.open(new ExecutionContext()); // fails, if resource is not set explicitly! ... Seems that dependency injection for the resource property of a FlatFileItemReader (or one of it's superclasses) does not work correctly. In practice, this workaround is useless because a you cannot access the ItemReader injected into a StepExecution before the open(...) method is called on an ItemReader. Thus there is not place to invoke setResource(...) on the ItemReader before it is actually used.

    Spring JIRA | 8 years ago | Oliver Theissen
    org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
  3. 0

    [BATCH-1266] FlatFileItemReader.open() fails if Resource is injected by the IoC container - Spring JIRA

    spring.io | 1 year ago
    org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Spring-batch and file upload

    Stack Overflow | 3 years ago | bontade
    org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
  6. 0

    SpringBatch - How to catch a Read Exception when resource doesn't exist

    Stack Overflow | 3 years ago | Armando
    org.springframework.batch.item.ItemStreamException: Failed to initialize the reader

    7 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Input resource must exist (reader is in 'strict' mode): class path resource [employeeResource]

      at org.springframework.batch.item.file.FlatFileItemReader.doOpen()
    2. Spring Batch Infrastructure
      AbstractItemCountingItemStreamItemReader.open
      1. org.springframework.batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:245)
      2. org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:108)
      2 frames
    3. batch.bug
      ItemReaderTest.main
      1. batch.bug.ItemReaderTest.testItemReader(ItemReaderTest.java:49)
      2. batch.bug.ItemReaderTest.main(ItemReaderTest.java:34)
      2 frames