Announcement Announcement Module
Collapse
No announcement yet.
Passing JobParameters to ItemWriters/Readers Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing JobParameters to ItemWriters/Readers

    Apologies if this has already been answered, but I have been unsuccessful finding it...
    I am trying to set-up an extraction job that will write records to a flat file. I am using FlatFileItemWriter however instead of hard-coding file name in the xml context for the writer's "resource" property I would like to be able to construct it at run time using job's JobParameters values.
    Can anybody please post an example on how this should be done.
    I am using version 2.0.1.
    Thanks
    Nash

  • #2
    You will want to use late-binding:

    Code:
    <bean id="flatFileItemReader" scope="step" 
          class="org.springframework.batch.item.file.FlatFileItemReader">
        <property name="resource" value="#{jobParameters[input.file.name]}" />
    </bean>
    Note that the bean must have scope="step".

    See: http://static.springframework.org/sp...l#late-binding

    Comment


    • #3
      I have a question on this late binding...

      I have a java bean whose main purpose is to get the file name dynamically (through late binding, as job parameter) and delete that file.

      I have the code as follows:
      Code:
      <beans:bean id="fileDeleter" class="com.batch.processor.DeleteFileProcessor">
       <beans:property name="filename" value="scripts/date_#{jobParameters[FILENAME]}.txt" />		
      	</beans:bean>
      It does not bind the variable it should say "scripts/date_filename.txt" but it is showing what i typed-in. Is there a special way to append values before and after the parameter?
      I am using 2.0

      Just to add an additional comment, my DeleteFileProcessor is a tasklet and it is defined as one of the steps in my job.
      Last edited by hailspring; Jun 26th, 2009, 10:15 AM.

      Comment


      • #4
        Have you tried it with scope="step" attribute added to your bean element?

        Comment


        • #5
          Yes that was the issue!! I tried with scope="step" and it worked!!

          Thanks a lot!!

          Comment

          Working...
          X