Results 1 to 8 of 8

Thread: How to read the resource File Name in Item processor/ItemWriter

  1. #1
    Join Date
    Dec 2010
    Posts
    6

    Question How to read the resource File Name in Item processor/ItemWriter

    Hello,

    I am doing a POC for one of my project with Spring batch. I am using flatFileItemReader to read the file and ceated my Custom Item Processor and ItemWriter. I have a requriement where I need to persist the resource file name with its full absoulte path in the database. I could not find any way to read the reader or its any of the attribute in ItemProcessor and/or ItemWriter.

    Please, help.

    Thanks in Advance.

  2. #2

    Default

    Perhaps it makes sense to read the resource directly from your spring context by implementing ApplicationContextAware. Or you can inject the same resource into two places, in FlatFileItemReader and also the ItemProcessor.

  3. #3
    Join Date
    Dec 2010
    Posts
    6

    Default

    Thanks Robert for your reply. On which class you suggestes to impelment ApplicationContextAware as we have the resoruce property with flatFileItemReader or on ItemProcessor.

    If we inject the same resource with ItemProcessor it will be kind of hardcoidng which I am doing right now and which is very error prone.

  4. #4

    Default

    I mean you can declare the resource as a standalone bean and inject this resource bean in both FlatFileItemReader and ItemProcessor. So you end up with single shared resource definition which shouldn't be error-prone at all.

  5. #5
    Join Date
    Dec 2010
    Posts
    6

    Default

    Resource is a property in FlatFileItemReader, I mean its a name of the file, its not a class. So, how can we define a bean for it?

    Folloiwng will not work as SIT001K is not a class but a simple flat file.
    <bean id="inputResource" value="com.sopra.evolansa.cardpayment.job.context. SIT001K"/>

  6. #6

    Default

    Here's an example:
    <bean id="res" class="org.springframework.core.io.FileSystemResou rce">
    <constructor-arg>test.txt</constructor-arg>
    </bean>

  7. #7
    Join Date
    Dec 2010
    Posts
    6

    Default

    But I am sorry to tell you that FlatFileItemReader take reasource as a property not as a Object. So we can not refer this to FlatFileItemReader.

    Though, I put resource in a property file as a property and refered it as a property in FlatFileItemReader & ItemProcessor.

    But I think it is not a best way to do it.

    I wonder why there is no way to read ExecutionContext inside a step. There are only two method afterStep and beforeStep where we can have that. But I need that at many places in between step. Like I want to know my currentIndex of reader.

    Any clues?

  8. #8
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    Robert's suggestion of using a Resource bean definition seems sensible to me, so I don't know why you think it won't work.

    Quote Originally Posted by goel_veenu View Post
    I wonder why there is no way to read ExecutionContext inside a step. There are only two method afterStep and beforeStep where we can have that. But I need that at many places in between step. Like I want to know my currentIndex of reader.
    You need an ItemStream?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •