title: Spring Batch persist data from step1 to step2
body: <p>I have thoroughly searched the Spring docs and supporting sites, but have not found and answer to this inquiry; if I want to access and store some values in the ExecutionContext, do I have to write custom databaseItemReader and ItemWriter's that implement the ItemStream or can I use the "out-of-the-box" readers and writers and edit the beans in the spring-batch-context.xml file to do this? Any code examples would be greatly appreciated. Thanks!</p>
  
  <p>http://www.springframework.org/schema/batch/spring-batch-3.0.xsd
          <a href="http://www.springframework.org/schema/beans" rel="nofollow">http://www.springframework.org/schema/beans</a> <a href="http://www.springframework.org/schema/beans/spring-beans-4.0.xsd" rel="nofollow">http://www.springframework.org/schema/beans/spring-beans-4.0.xsd</a>"></p>
  
  <pre><code>&lt;import resource="classpath:context-datasource.xml" /&gt;
  
  &lt;!-- JobRepository and JobLauncher are configuration/setup classes --&gt;
  &lt;bean id="jobRepository"
      class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean" /&gt;
  
  &lt;bean id="jobLauncher"
      class="org.springframework.batch.core.launch.support.SimpleJobLauncher"&gt;
      &lt;property name="jobRepository" ref="jobRepository" /&gt;
  &lt;/bean&gt;
  
  
  &lt;!-- ItemReader which reads from database and returns the row mapped by 
      rowMapper --&gt;
  &lt;bean id="databaseItemReader"
      class="org.springframework.batch.item.database.JdbcCursorItemReader"&gt;
  
      &lt;property name="dataSource" ref="dataSource" /&gt;
  
      &lt;property name="sql"
          value="SELECT PartnerID, ftpUserName, ftpPassword, ftpPath, jobRunTime, jobFrequency FROM tblRosterJobParams" /&gt;
  
      &lt;property name="rowMapper"&gt;
          &lt;bean class="com.explorelearning.batch.ParamResultRowMapper" /&gt;
      &lt;/property&gt;
  
  &lt;/bean&gt;
  
  
  &lt;!-- This was supposed to change to a SavingItemWriter that persists these values to the Step ExecutionContext --&gt;
  &lt;bean id="flatFileItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter"
      scope="step"&gt;
  
      &lt;property name="resource" value="file:csv/ParamResult.txt" /&gt;
  
      &lt;property name="lineAggregator"&gt;
  
          &lt;!--An Aggregator which converts an object into delimited list of strings --&gt;
          &lt;bean
              class="org.springframework.batch.item.file.transform.DelimitedLineAggregator"&gt;
  
              &lt;property name="delimiter" value="," /&gt;
  
              &lt;property name="fieldExtractor"&gt;
  
                  &lt;!-- Extractor which returns the value of beans property through reflection --&gt;
                  &lt;bean
                      class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor"&gt;
                      &lt;property name="names" value="PartnerID" /&gt;
                  &lt;/bean&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Optional JobExecutionListener to perform business logic before and after the job --&gt;
  &lt;bean id="jobListener" class="com.explorelearning.batch.RosterBatchJobListener" /&gt;
  
  &lt;!-- Optional StepExecutionListener to perform business logic before and after the job --&gt;
  &lt;bean id="stepExecutionListener" class="com.explorelearning.batch.ParamResultStepExecutionListener" /&gt;
  
  &lt;!-- Optional ItemProcessor to perform business logic/filtering on the input records --&gt;
  &lt;bean id="itemProcessor" class="com.explorelearning.batch.ParamResultItemProcessor" /&gt;
  
  &lt;!-- Step will need a transaction manager --&gt;
  &lt;bean id="transactionManager"
      class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" /&gt;
  
  &lt;!-- Actual Job --&gt;
  &lt;batch:job-repository id="jobRepository"  data-source="dataSource" table-prefix="BATCH_"
      transaction-manager="transactionManager" isolation-level-for-create="SERIALIZABLE" /&gt;
  &lt;batch:job id="RosterBatchJob" job-repository="jobRepository"&gt;
   &lt;batch:step id="readParams" &gt;
      &lt;batch:tasklet transaction-manager="transactionManager" allow-start-if-complete="true"&gt;
          &lt;batch:chunk reader="databaseItemReader"  writer="flatFileItemWriter"
              processor="itemProcessor" commit-interval="10" /&gt;
      &lt;/batch:tasklet&gt;
   &lt;/batch:step&gt;
   &lt;!--&lt;batch:step id="grabCSVs" next="validateCSVs"&gt;
  
   &lt;/batch:step&gt;
   &lt;batch:step id="validateCSVs" next="filterRecords"&gt;
  
   &lt;/step&gt;
   &lt;batch:step id="filterRecords" next="determineActions"&gt;
  
   &lt;/batch:step&gt;
    &lt;batch:step id="determineActions" next="executeActions"&gt;
  
   &lt;/batch:step&gt;
    &lt;batch:step id="executeActions" next=""&gt;
  
   &lt;/batch:step&gt;  --&gt;
  
  &lt;/batch:job&gt; 
  </code></pre>
  
  <p>            </p>