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配置文件。
我不非常瞭解JavaConfig,但我想partitioner()並不會自動註冊爲監聽器,但是您必須手動註冊 –
感謝@LucaBassoRicci,你有什麼想法該怎麼做?是足夠的註釋還是我需要XML配置? –
我想你可以在StepBuilder中找到一個listener()方法 –