我有大师步
@Bean
public Step employeeMasterProfilePhoneStep() throws UnexpectedInputException, ParseException {
return stepBuilderFactory.get(Constant.MASTER_PHONE_STEP)
.partitioner(Constant.PARTITIONER_STEPNAME_WORKERSTEP, employeeProfilePhonePartitioner())
.listener(employeeProfileStepListener())
.step(employeeProfilePhoneStep())
.taskExecutor(employeeProfileTaskExecutor())
.gridSize(20)
.build();
}
工人步骤
@Bean
public Step userProfilePhoneStep() {
return stepBuilderFactory.get("userProfilePhoneStep")
.<UserProfile, UserProfile>chunk(2000)
.reader(custPhonePeekingReader())
.processor(employeeProfileProcessor())
.writer(employeeProfileItemWriter)
.listener(ItemReaderListener)
.listener(ChunkListener)
.build();
}
Stepscope on 方法,该方法根据分区器中的执行上下文数量创建对象(在我的例子中,我有 3 个执行上下文)
@Bean
@StepScope
public CustPhonePeekingReader custPhonePeekingReader() {
return new CustPhonePeekingReader();
}
我的 custPhonePeekingReader() 永远不会从工作步骤中调用,即使它应该创建 3 个对象,因为我在分区器中创建了 3 个执行上下文。
但是,如果我将方法名称更改为 customerPhonePeekingReader 或“custPhonePeekingReader”以外的任何名称,则工作步骤能够调用并创建 3 个 CustPhonePeekingReader 实例。 bean 名称有任何问题或冲突吗?非常感谢任何帮助
在您的主要步骤中,您有:
.step(employeeProfilePhoneStep())
但是工人步骤被称为
userProfilePhoneStep()
。这是不正确的。
对于读者来说,由于您在这里使用方法调用来设置 bean
.reader(custPhonePeekingReader())
,所以您所描述的情况不应该发生。您没有共享所有代码,因此问题应该在其他地方。
你可以尝试像这样注入阅读器:
@Bean
public Step userProfilePhoneStep(CustPhonePeekingReader custPhonePeekingReader) {
return stepBuilderFactory.get("userProfilePhoneStep")
.<UserProfile, UserProfile>chunk(2000)
.reader(custPhonePeekingReader)
.processor(employeeProfileProcessor())
.writer(employeeProfileItemWriter)
.listener(ItemReaderListener)
.listener(ChunkListener)
.build();
}
我会对处理器和写入器做同样的事情。