Announcement Announcement Module
No announcement yet.
Flow Question Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Flow Question

    I have the following scenario that I am trying to figure out. I am reading in a fixed length file and here are my steps. Problem is I am not fully understanding how to pass my Entity model around.

    Here are the steps I am trying to perform.
    1) Create a fileEntity object based on the filename of the incoming file to read. (got this done, no problem)
    2) start reading the fixed length file in and for each row, create a detailRecordEntity (no parsing, the full line is the entity). Then the fileEntity contains a "list" of detailRecordEntity (one to many) so I need to take the fileEntity and pass it to the detailRecordEntity for the relationship, then persist the detailRecordEntity.

    Currently I am creating the fileEntity and putting it into the stepContext for referencing.

    So my question is: when I am reading and writing, how can I get access to the stepContext to get my fileEntity reference? below is my attempt at reading my lines which works, but no where to grab the context?

    <bean id="batchFileReader" class="org.springframework.batch.item.file.FlatFil eItemReader" scope="step">
    [inputBatchFile]}" /> -->
    <property name="resource" value="classpath:#{jobParameters[inputBatchFile]}" />
    <property name="lineMapper">
    <bean class="org.springframework.batch.item.file.mapping .PassThroughLineMapper" />


  • #2
    To access the StepContext from an object, you just need to inject it:

    <bean id="myBean" class="someClassWithAStepContextAttribute">
        <property name="stepContext" value="#{stepContext}"/>


    • #3
      I tried this, but still receiving error. In my listener I added a getter and a setter for the "stepContext".

      Here is my job .xml

      <bean id="processedJobTasklet" class="com.foobar.CheckCompletedJobsTasklet" scope="step" />

      <bean id="checkForProcessedFilesListener" class="com.foobar.listener.CheckForProcessedFilesL istener" >
      <property name="stepContext" value="#{stepContext}"/>
      I just want to be able to take a variable from the Tasklet and pass it to a listener. I am missing something.
      In my Listener I just injected the Stepcontext with getters and setters like so:

      StepContext stepContext = null;
      public StepContext getStepContext() {
      return stepContext;

      * @param stepContext the stepContext to set
      public void setStepContext(StepContext stepContext) {
      this.stepContext = stepContext;


      • #4
        Your step needs to be step scoped to have that be injected.