Step表示作业中的一个完整步骤,一个Job可以由一个或者多个Step组成。Step的声明使用Step元素声明,每个Step由tasklet元素描述具体的作业,tasklet可以是一个自定义业务处理(需要实现接口org.springframework.batch.core.step.tasklet.Tasklet),也可以使用chunk元素描述面向块的业务处理,一个典型的chunk包含read、process和write三个操作。
1.tasklet是一个自定义业务处理的声明方式
<!--定义job-->
<batch:job id="demo4Job">
<batch:step id="demo4Step">
<batch:tasklet ref="jobParametersTasklet"/>
</batch:step>
</batch:job>
参考:Spring Batch之Job Parameters校验(五)_人……杰的博客-CSDN博客
2.使用chunk元素的声明方式
<!--定义名字为billJob的作业-->
<batch:job id="billJob">
<!--定义名字为billStep的作业步-->
<batch:step id="billStep">
<batch:tasklet transaction-manager="transactionManager">
<!--定义读、处理、写操作,规定每处理两条数据,进行一次写入操作,这样可以提高写的效率-->
<batch:chunk reader="csvItemReader" processor="creditBillProcessor" writer="csvItemWriter" commit-interval="2">
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>