2017-04-13 63 views
0

我有這個工作,但運行時,分區程序中的beforeStep方法從不調用。我究竟做錯了什麼?分區程序實現StepExecutionListener,但不調用BeforeStep

@Configuration 
public class SomeJob { 

@Bean(name = "some-job") 
public Job job() { 
    return jobBuilderFactory.get(getName()) 
      .incrementer(new RunIdIncrementer()) 
      .start(stepOne()) 
      .next(stepTwo()) 
      .build(); 
} 

private Step stepOne() { 
    TaskletStep stepOne = stepBuilderFactory 
      .get("step-one") 
      .<...>chunk(CHUNK_SIZE) 
      .reader(someReader()) 
      .writer(someWriter()) 
      .build(); 

    return stepBuilderFactory 
      .get("partitionedStepOne") 
      .partitioner(stepOne) 
      .partitioner("partition", partitioner()) 
      .taskExecutor(someExecutor()) 
      .gridSize(SIZE) 
      .build(); 
} 


@Bean 
@Scope(value = "step", proxyMode = ScopedProxyMode.TARGET_CLASS) 
Partitioner partitioner() { 
    return new OffsetBasedPartitioner(NAME, storedArticleMasterDataRepository); 
} 
} // end of job class 
.... 

public class OffsetBasedPartitioner implements Partitioner, StepExecutionListener { 

@Override 
public void beforeStep(StepExecution stepExecution) { 
    ... 
} 
... 
} 

如果可能的話我會避免XML配置文件。

+2

我不非常瞭解JavaConfig,但我想partitioner()並不會自動註冊爲監聽器,但是您必須手動註冊 –

+0

感謝@LucaBassoRicci,你有什麼想法該怎麼做?是足夠的註釋還是我需要XML配置? –

+1

我想你可以在StepBuilder中找到一個listener()方法 –

回答

0

感謝@LucaBassoRicci他的建議下,我加入了分區作爲步驟定義監聽器:

return stepBuilderFactory 
     .get("partitionedStepOne") 
     .partitioner(stepOne) 
     .partitioner("partition", partitioner()) 
     .listener(partitioner()) 
     .taskExecutor(someExecutor()) 
     .gridSize(SIZE) 
     .build(); 

,離開所有的休息如上,現在工程:)

相關問題