質問

I have three level hierarchy of jobs.

<job id="job1">     
    <step id="step1" >
        <job ref="step1.job1.1" job-parameters-extractor="job1Parameters"/>
    </step>     
</job>


<job id="job1.1">       
    <step id="step1.1" >
        <job ref="step1.1.job1.1.1"/>
    </step> 
</job>


<job id="job1.1.1">     
    <step id="step1.1.1" >
        <tasklet ref="ste1.1.1Tasklet" />
    </step>     
</job>

I want to pass param1=value1 parameters from top level job (job1) to job1.1 and which should again pass it to job1.1.1 ?

How it can be done in spring batch ? I was trying to use

<util:map id="job1Parameters"
    map-class="org.springframework.beans.factory.config.MapFactoryBean">
    <beans:entry key="param1" value="value1" />
</util:map>

<beans:bean id="otherComputeJobParametersExtractor"
    class="org.springframework.batch.core.step.job.DefaultJobParametersExtractor"
    p:keys-ref="job1Parameters" />

But its not working.

I know I can pass it as a parameter to job1 and it will be automatically passed to child jobs but there are many parameters and many of those are only for sepecific child jobs so I dont want to pass all parameters to job1.

Can we add any step listener which will add param1=value1 in stepExecutionContext just before triggering child job so the parameters are available to child job via stepExecutionContext ?

役に立ちましたか?

解決

I could do it using by setting up stepExecutionListener to pur param1=value1 in stepExecutionContext.

public class SetParam1StepListener implements StepExecutionListener {

    protected String param1;

    public String getParam1() {
        return param1;
    }

    public void setParam1(String param1) {
        this.param1 = param1;
    }

    @Override
    public ExitStatus afterStep(StepExecution stepExecution) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void beforeStep(StepExecution stepExecution) {
        stepExecution.getExecutionContext().put("param1", this.param1); 

    }

}



<beans:bean id="value1.setParam1StepListener" class="com.my.SetParam1StepListener" p:param1="value1" />

Then by adding param1 key to jobParameterExtractor

<beans:bean id="jobParametersExtractor"
    class="org.springframework.batch.core.step.job.DefaultJobParametersExtractor">
    <beans:property name="keys" value="param1" />
</beans:bean>

and then passing it to step job

<job id="job1">     
    <step id="step1" >
        <job ref="step1.job1.1" job-parameters-extractor="jobParametersExtractor"/>
        <listeners>
            <listener ref="value1.setParam1StepListener" />
        </listeners>
    </step>     
</job>

It works.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top