Spring Batch:如何在XML配置中指定一个步骤的类?

时间:2016-01-05 15:40:36

标签: java spring spring-batch

在XML配置中,我们可以添加一个步骤。我们可以这样做:

<batch:step id="MyCoolStep"> ... </batch:step>

但是如何指定步骤的类?

我想写这样的东西

<batch:step id="MyCoolStep" class="com.test.batch.MyCoolStep"> ... </batch:step>

MyCoolStepTaskletStep

2 个答案:

答案 0 :(得分:1)

假设您的班级MyCoolStep实施Tasklet,您可以定义步骤like this

<batch:step id="MyCoolStep">
  <batch:tasklet>
    <bean class="com.test.batch.MyCoolStep" />
  </batch:tasklet>
</batch:step>

无需先前明确定义<bean>并通过id引用它。

但直截了当的做法是:

<bean id="myCoolStepBean" class="com.test.batch.MyCoolStep" />

<batch:step id="MyCoolStep">
  <batch:tasklet ref="myCoolStepBean" />
</batch:step>

答案 1 :(得分:0)

正如Tunaki所指出的,如果你的步骤是Tasklet,你可以这样做:

<batch:step id="MyCoolStep">
    <batch:tasklet>
        <bean class="com.test.batch.MyCoolStep" scope="step" />
    </batch:tasklet>
</batch:step>
相关问题