Announcement Announcement Module
Collapse
No announcement yet.
FlatFileItemReader, org.springframework.batch.item.ReaderNotOpenExcept ion Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FlatFileItemReader, org.springframework.batch.item.ReaderNotOpenExcept ion

    org.springframework.batch.item.ReaderNotOpenExcept ion: Reader must be open before it can be read. I'm using spring-batch-infrastructure-2.0.4.RELEASE.jar

    I'm new to spring batch and did some investigation by reading reference doc.
    I'm using FlatFileItemReader and unit testing my code for XXXItemFieldSetMapper. fileItemReader.read() threw the about error message.

    @Before
    public void setUp() throws Exception {
    myItemReader = new FlatFileItemReader();
    /***set lineMapper etc***/
    matchingItems = new ArrayList<CSVSettlementMatchingItem>();
    myItemReader.setResource(new FileSystemResource("resources/data.csv"));
    }
    @Test
    public void testRead() throws Exception{
    for(MyItem item: matchingItems) {
    matchingItem.equals(myItemReader.read());
    }
    }

    It was a bug but was fixed(see the link). but I'm using v2.0.4. and will set scope=step for my FlatFileItemReader. Please help and thanks in advance
    https://jira.springsource.org/browse...ream-issue-tab

  • #2
    You aren't using a FlatFileItemReader configured in xml, you are configuring/instantiating one yourself. This also means that you must simulate the batch lifecycle and also honour the ItemStream contract. So either use a FlatFileItemReader configured in xml or call the lifecycle methods yourself.

    Comment


    • #3
      Thanks for your quick response and help. Could you please let me know where I can find information to call the lifecycle method myself (in order to honour the ItemStream)? Thank you very much.

      Comment


      • #4
        For starters after setting the properties you need to call the afterPropertiesSet method (it is an InitializingBean). Before you start reading in your loop you need to call the open method (with an ExecutionContext). I suggest you take a look at the API (JavaDocs) or the sources, you also might want to look at the ChunkOrientedTasklet and related classes to get a feel for the lifecycle...

        Comment


        • #5
          Thanks for your detailed reply.

          Comment

          Working...
          X