spring - 如何使用 CompositeItemProcessor 在处理器中获取 stepExecutionContext?
问题描述
在 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
解决方案
在您的处理器中尝试以下操作。
@Value("#{stepExecution}")
private StepExecution stepExecution;
如果范围是步骤,这应该有效。
推荐阅读
- jquery - 在 jquery 字符串中,我想传递字段值而不是常量作为参数
- pandas - 基于第三列的差异熊猫数据框列的条件
- javascript - 异步等待阻止其他功能运行
- powerbi - 如何以 Excel 格式下载整个 PowerBi 报告
- arrays - 无法过滤另一个数组中的空数组(打字稿)
- java - Jackson 序列化和反序列化 Map
- mysql - sql查询,返回所有比他们认识的人大5岁以上的人
- python - 如何使用python获得回归线上一点的置信区间?
- reactjs - “模板字符串中不允许使用八进制转义序列”错误,当我在 spxf 中进行 gulp 构建时(反应)
- c# - C# / Moq - 如何强制异常并一步返回值