Results 1 to 3 of 3

Thread: FlatFileHeaderCallback with access to ExecutionContext

  1. #1
    Join Date
    Oct 2012
    Posts
    7

    Default FlatFileHeaderCallback with access to ExecutionContext

    Hello.

    I'm using FlatFileItemWriter with FlatFileHeaderCallback. My FlatFileHeaderCallback needs to retrieve some values from the ExecutionContext. How will my FlatFileHeaderCallback implementation gain access to the ExecutionContext?

    I tried implementing the StepExecutionListener and the ItemStream, but none of their methods were called.

    Alternative approaches I see seem to look more like a workaround:
    1. Create an ItemWriter that either extends or wraps a FlatFileItemWriter, and override or implement either StepExecutionListener or ItemStream to get the ExecutionContext and pass it to the FlatFileHeaderCallback implementation's constructor.
    2. Add a StepExecutionListener in the step and pass the FlatFileHeaderCallback implementation. StepExecutionListener will then set the ExecutionContext.

    Any suggestions?

    Thanks!

  2. #2
    Join Date
    Aug 2011
    Posts
    20

    Default

    You can inject the values directly from the ExecutionContext into the header callback with SpEL expressions if you use scope="step".

    Code:
    <bean id="headerCallback" class="MyHeaderCallback" scope="step">
        <property name="foo" value="#{jobExecutionContext['foo']}" />
    </bean>
    The StepExecutionListener or ItemStream approaches should work too, but you need to register them properly in your step configuration.

  3. #3
    Join Date
    Oct 2012
    Posts
    7

    Default

    Great, thanks jpraet for the suggestion. I referred back to the documentation.
    Also, I actually forgot to register the one implementing the StepExecutionListener, and it now works.

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
  •