2013-10-03 1 views
0

나는 스프링 배치에 대해 상당히 익숙하며 일부 방향은 고맙겠습니다.스프링 배치 : 데이터를 기반으로하는 프로세서로의 대표자

청크 프로세서를 사용하고 있습니다. 파일 이름에 따라 특정 프로세서를 선택하는 작업을 만들고 싶습니다. 예를 들어

: 파일의 경우 : testfile 위 - 1.TXT 사용 프로세서 : TestFileProcessor1.java 파일의 경우 : testfile 위-2.txt 사용 프로세서 : TestFileProcessor2.java

난 단지 ONE 청크 프로세서를 갖는이 선호

도와 주셔서 감사합니다

답변

0

에 대한 올바른 프로세서의 이전 작업 후크 당신은 단계를 해결하기 위해 코드를 흐르게하는 JobExecutionDecider를 사용할 수 있습니다.
당신은 추상적 인 단계 (BaseStep) 독자와 작가가 정의되지 않지만 프로세서를 가지고 올바른 프로세서

<batch:step id="StepTestFile1" parent="BaseStep"> 
    <batch:processor ref="path.to.TestFileProcessor1" /> 
</batch:step> 

등을 바인딩 3 구체적인 단계를 정의했다.
JobExecutionDecider에서 파일 이름 (의사 코드)을 기준으로 올바른 단계를 수행 할 수 있습니다.

class MyDecider implements JobExecutionDecider { 
    public FlowExecutionStatus decide(JobExecution jobExecution,StepExecution stepExecution) { 
    if(filename is testfile-1.txt) return new FlowExecutionStatus("StepTestFile1"); 
    if(filename is testfile-2.txt) return new FlowExecutionStatus("StepTestFile2"); 
    if(filename is testfile-3.txt) return new FlowExecutionStatus("StepTestFile3"); 
    } 
}