복붙노트

[SPRING] Spring-Batch : 다음 단계를 결정하기 위해 StepListener에서 사용자 정의 Job Exit STATUS를 리턴하려면 어떻게해야합니까?

SPRING

Spring-Batch : 다음 단계를 결정하기 위해 StepListener에서 사용자 정의 Job Exit STATUS를 리턴하려면 어떻게해야합니까?

문제는 다음과 같습니다. 스프링 배치 작업이 여러 단계로 이루어졌습니다. 1 단계를 기준으로 다음 단계를 결정해야합니다. STEP1-passTasklet에 작업 매개 변수를 기반으로 상태를 설정하여 종료 상태를 사용자 정의 상태로 설정하고 작업 정의 파일에서 정의하여 다음 단계로 넘어갈 수 있습니까?

Example
<job id="conditionalStepLogicJob">
<step id="step1">
<tasklet ref="passTasklet"/>
<next on="BABY" to="step2a"/>
<stop on="KID" to="step2b"/>
<next on="*" to="step3"/>
</step>
<step id="step2b">
<tasklet ref="kidTasklet"/>
</step>
<step id="step2a">
<tasklet ref="babyTasklet"/>
</step>
<step id="step3">
<tasklet ref="babykidTasklet"/>
</step>
</job>

내가 이상적으로 자신의 종료 상태가 단계 사이에 사용되기를 원합니다. 내가 할 수 있을까? OOTB 흐름을 깨뜨리지 않을 것인가? 그것을하는 것이 타당한가?

해결법

  1. ==============================

    1.이 방법은 여러 가지 방법으로이를 수행합니다.

    이 방법은 여러 가지 방법으로이를 수행합니다.

    StepExecutionListener를 사용하고 afterStep 메서드를 재정의 할 수 있습니다.

    @AfterStep
    public ExitStatus afterStep(){
        //Test condition
        return new ExistStatus("CUSTOM EXIT STATUS");
    }
    

    또는 JobExecutionDecider를 사용하여 결과에 따라 다음 단계를 선택할 수 있습니다.

    public class CustomDecider implements JobExecutionDecider  {
    
        public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
            if (/* your conditon */) {
                return new FlowExecutionStatus("OK");
            }
            return new FlowExecutionStatus("OTHER CODE HERE");
        }
    
    }
    

    Xml 구성 :

        <decision id="decider" decider="decider">
            <next on="OK" to="step1" />
            <next on="OHTER CODE HERE" to="step2" />
        </decision>
    
    <bean id="decider" class="com.xxx.CustomDecider"/>
    
  2. from https://stackoverflow.com/questions/15411731/spring-batch-how-do-i-return-a-custom-job-exit-status-from-a-steplistener-to-de by cc-by-sa and MIT license