Announcement Announcement Module
No announcement yet.
FlatFileHeaderCallback with access to ExecutionContext Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • FlatFileHeaderCallback with access to ExecutionContext


    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?


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

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


    • #3
      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.