[英]Spring Batch: How to access the current step's id / name from within an ItemReader or ItemWriter
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? 我对Spring-Batch很陌生,我想知道是否可以通过ItemReader或ItemWriter 访问step-id ?
In my case that would allow switching enum types based on different step-definitions in a single ItemReader implementation. 就我而言,这将允许在单个ItemReader实现中基于不同的步骤定义切换枚举类型。
Does anyone know a way to do that? 有人知道这样做的方法吗?
Assuming the ItemReader or ItemWriter are step scoped, you can do this: 假设ItemReader或ItemWriter是步骤范围的,则可以执行以下操作:
<bean id="flatFileItemReader" scope="step"
class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource" value="#{stepExecution.stepName}" />
</bean>
It is as simple as implementing a with @BeforeStep
annotated method: 这与使用
@BeforeStep
注释方法实现一样简单:
@BeforeStep
public void beforeStep(StepExecution stepExecution){
String name = stepExecution.getStepName();
System.out.println("name: " + name);
}
Placed it in my ItemReader and that's it ... 将其放在我的ItemReader中 ,就这样...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.