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

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

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

    &lt;processor&gt;
          &lt;beans:bean id=&quot;CompositeItemProcessor&quot; class=&quot;org.springframework.batch.item.support.CompositeItemProcessor&quot; scope=&quot;step&quot;&gt;
            &lt;beans:property name=&quot;delegates&quot;&gt;
              &lt;beans:list&gt;
                &lt;beans:ref bean=&quot;oldProcessor&quot;/&gt;
                &lt;beans:ref bean=&quot;newProcessor&quot;/&gt;
              &lt;/beans:list&gt;
            &lt;/beans:property&gt;
          &lt;/beans:bean&gt;
        &lt;/processor&gt;

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.

&lt;processor&gt;
    &lt;beans:ref bean=&quot;oldProcessor&quot;/&gt;
&lt;/processor&gt;

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(&quot;#{stepExecution}&quot;)

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:

确定