如何在使用CompositeItemProcessor的处理器中获取stepExecutionContext?

huangapple go评论93阅读模式
英文:

How to get stepExecutionContext in Processor using CompositeItemProcessor?

问题

In XML文件中,我配置了两个处理器,使用CompositeItemProcessor

  1. <processor>
  2. <beans:bean id="CompositeItemProcessor" class="org.springframework.batch.item.support.CompositeItemProcessor" scope="step">
  3. <beans:property name="delegates">
  4. <beans:list>
  5. <beans:ref bean="oldProcessor"/>
  6. <beans:ref bean="newProcessor"/>
  7. </beans:list>
  8. </beans:property>
  9. </beans:bean>
  10. </processor>

oldProcessor bean的Java文件中,我添加了以下代码来获取StepExecution对象:

  1. @BeforeStep
  2. @Order(1)
  3. public void setStepExecution(StepExecution stepExecution) {
  4. this.stepExecution = stepExecution;
  5. }

但是上面的代码没有执行。只有oldProcessor bean中的**process()**方法被调用。

当我尝试不配置CompositeItemProcessor时,setStepExecution()方法和process()方法都会在oldProcessor bean中执行。例如:

  1. <processor>
  2. <beans:ref bean="oldProcessor"/>
  3. </processor>

请告诉我,如何在使用CompositeItemProcessor的处理器中获取stepExecutionContext。

英文:

In XML file i have configured two Processor using CompositeItemProcessor

  1. &lt;processor&gt;
  2. &lt;beans:bean id=&quot;CompositeItemProcessor&quot; class=&quot;org.springframework.batch.item.support.CompositeItemProcessor&quot; scope=&quot;step&quot;&gt;
  3. &lt;beans:property name=&quot;delegates&quot;&gt;
  4. &lt;beans:list&gt;
  5. &lt;beans:ref bean=&quot;oldProcessor&quot;/&gt;
  6. &lt;beans:ref bean=&quot;newProcessor&quot;/&gt;
  7. &lt;/beans:list&gt;
  8. &lt;/beans:property&gt;
  9. &lt;/beans:bean&gt;
  10. &lt;/processor&gt;

and in "oldProcessor" bean java file i have added below code to get StepExecution object.

  1. @BeforeStep
  2. @Order(1)
  3. public void setStepExecution(StepExecution stepExecution) {
  4. this.stepExecution = stepExecution;
  5. }

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.

  1. &lt;processor&gt;
  2. &lt;beans:ref bean=&quot;oldProcessor&quot;/&gt;
  3. &lt;/processor&gt;

Please advise me, how to get stepExecutionContext in Processor using CompositeItemProcessor

答案1

得分: 1

以下是翻译好的内容:

尝试使用以下内容在您的处理器中。

  1. @Value("#{stepExecution}")
  2. private StepExecution stepExecution;

如果范围是步骤,这应该有效。

英文:

Try with the following in your processor.

  1. @Value(&quot;#{stepExecution}&quot;)
  2. private StepExecution stepExecution;

This should work if the scope is step.

huangapple
  • 本文由 发表于 2020年1月6日 15:18:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/59608099.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定