问题
I am quite new to Spring-Batch and I wonder whether there is a way to access the step-id from within an ItemReader or ItemWriter?
In my case that would allow switching enum types based on different step-definitions in a single ItemReader implementation.
Does anyone know a way to do that?
回答1:
Assuming the ItemReader or ItemWriter are step scoped, you can do this:
<bean id="flatFileItemReader" scope="step"
class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource" value="#{stepExecution.stepName}" />
</bean>
回答2:
It is as simple as implementing a with @BeforeStep annotated method:
@BeforeStep
public void beforeStep(StepExecution stepExecution){
String name = stepExecution.getStepName();
System.out.println("name: " + name);
}
Placed it in my ItemReader and that's it ...
来源:https://stackoverflow.com/questions/20838522/spring-batch-how-to-access-the-current-steps-id-name-from-within-an-itemread