Configuring a Step
Despite the relatively short list of required dependencies for a Step, it is an
extremely complex class that can potentially contain many collaborators.
- 
Java 
- 
XML 
When using Java configuration, you can use the Spring Batch builders, as the following example shows:
Java Configuration
/**
 * Note the JobRepository is typically autowired in and not needed to be explicitly
 * configured
 */
@Bean
public Job sampleJob(JobRepository jobRepository, Step sampleStep) {
    return new JobBuilder("sampleJob", jobRepository)
                .start(sampleStep)
                .build();
}
/**
 * Note the TransactionManager is typically autowired in and not needed to be explicitly
 * configured
 */
@Bean
public Step sampleStep(JobRepository jobRepository, (2)
		PlatformTransactionManager transactionManager) { (1)
	return new StepBuilder("sampleStep", jobRepository)
				.<String, String>chunk(10, transactionManager) (3)
				.reader(itemReader())
				.writer(itemWriter())
				.build();
}| 1 | transactionManager: Spring’sPlatformTransactionManagerthat begins and commits
transactions during processing. | 
| 2 | repository: The Java-specific name of theJobRepositorythat periodically stores
theStepExecutionandExecutionContextduring processing (just before committing). | 
| 3 | chunk: The Java-specific name of the dependency that indicates that this is an
item-based step and the number of items to be processed before the transaction is
committed. | 
| Note that repositorydefaults tojobRepository(provided through@EnableBatchProcessing)
andtransactionManagerdefaults totransactionManager(provided from the application context).
Also, theItemProcessoris optional, since the item could be
directly passed from the reader to the writer. | 
To ease configuration, you can use the Spring Batch XML namespace, as the following example shows:
XML Configuration
<job id="sampleJob" job-repository="jobRepository"> (2)
    <step id="step1">
        <tasklet transaction-manager="transactionManager"> (1)
            <chunk reader="itemReader" writer="itemWriter" commit-interval="10"/> (3)
        </tasklet>
    </step>
</job>| 1 | transaction-manager: Spring’sPlatformTransactionManagerthat begins and commits
transactions during processing. | 
| 2 | job-repository: The XML-specific name of theJobRepositorythat periodically stores
theStepExecutionandExecutionContextduring processing (just before committing). For
an in-line<step/>(one defined within a<job/>), it is an attribute on the<job/>element. For a standalone<step/>, it is defined as an attribute of the<tasklet/>. | 
| 3 | commit-interval: The XML-specific name of the number of items to be processed
before the transaction is committed. | 
| Note that job-repositorydefaults tojobRepositoryandtransaction-managerdefaults totransactionManager. Also, theItemProcessoris
optional, since the item could be directly passed from the reader to the writer. | 
The preceding configuration includes the only required dependencies to create a item-oriented step:
- 
reader: TheItemReaderthat provides items for processing.
- 
writer: TheItemWriterthat processes the items provided by theItemReader.