英文:
How to get stepExecutionContext in Processor using CompositeItemProcessor?
问题
In XML文件中,我配置了两个处理器,使用CompositeItemProcessor:
<processor>
<beans:bean id="CompositeItemProcessor" class="org.springframework.batch.item.support.CompositeItemProcessor" scope="step">
<beans:property name="delegates">
<beans:list>
<beans:ref bean="oldProcessor"/>
<beans:ref bean="newProcessor"/>
</beans:list>
</beans:property>
</beans:bean>
</processor>
在oldProcessor bean的Java文件中,我添加了以下代码来获取StepExecution对象:
@BeforeStep
@Order(1)
public void setStepExecution(StepExecution stepExecution) {
this.stepExecution = stepExecution;
}
但是上面的代码没有执行。只有oldProcessor bean中的**process()**方法被调用。
当我尝试不配置CompositeItemProcessor时,setStepExecution()方法和process()方法都会在oldProcessor bean中执行。例如:
<processor>
<beans:ref bean="oldProcessor"/>
</processor>
请告诉我,如何在使用CompositeItemProcessor的处理器中获取stepExecutionContext。
英文:
In XML file i have configured two Processor using CompositeItemProcessor
<processor>
<beans:bean id="CompositeItemProcessor" class="org.springframework.batch.item.support.CompositeItemProcessor" scope="step">
<beans:property name="delegates">
<beans:list>
<beans:ref bean="oldProcessor"/>
<beans:ref bean="newProcessor"/>
</beans:list>
</beans:property>
</beans:bean>
</processor>
and in "oldProcessor" bean java file i have added below code to get StepExecution object.
@BeforeStep
@Order(1)
public void setStepExecution(StepExecution stepExecution) {
this.stepExecution = stepExecution;
}
but above code not executing. only process() method calling from "oldProcessor" bean.
and when i tried without configuring CompositeItemProcessor,then this "setStepExecution()" method and process() method are executing of oldProcessor bean.
eg.
<processor>
<beans:ref bean="oldProcessor"/>
</processor>
Please advise me, how to get stepExecutionContext in Processor using CompositeItemProcessor
答案1
得分: 1
以下是翻译好的内容:
尝试使用以下内容在您的处理器中。
@Value("#{stepExecution}")
private StepExecution stepExecution;
如果范围是步骤,这应该有效。
英文:
Try with the following in your processor.
@Value("#{stepExecution}")
private StepExecution stepExecution;
This should work if the scope is step.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论