I have a snipped as mentioned below for step processing.
@Bean
@JobScope
public Step readStep(StepBuilderFactory sbf,
ItemReader reader,ItemWriter writer, TaskExecutor taskExecutor,
RefFileReaderComponentFactory componentFactory, String file){
final Step step = sbf.get(file)
.chunk(100)
.reader(reader)
.faultTolerant()
.skipPolicy(new SkipPolicy()) //dummy skip policy for representation purpose
.writer(writer)
.faultTolerant()
.skipPolicy(new SkipPolicy())
.listener(new NewStepExecutionListener()) //This dummy listener is implementation of the StepExecutionListener
//.listener(new NewItemWrtieListener) //This dummy listener is implementation of the ItemWriteListener
.taskExecutor(taskExecutor)
.build();
return step;
}
But the above code throws compile time error - The method taskExecutor(TaskExecutor) is undefined for the type StepBuilderHelper
.
Interestingly, this error is only shown when I put NewStepExecutionListener
listener but if I comment it out and uncomment NewItemWrtieListener
then it works fine.
Post typecasting, code looks like this:
@Bean
@JobScope
public Step readStep(StepBuilderFactory sbf,
ItemReader reader,ItemWriter writer, TaskExecutor taskExecutor,
RefFileReaderComponentFactory componentFactory, String file){
final Step step = ((AbstractTaskletStepBuilder<SimpleStepBuilder<Object, Object>>) sbf.get(file)
.chunk(100)
.reader(reader)
.faultTolerant()
.skipPolicy(new SkipPolicy()) //dummy skip policy for representation purpose
.writer(writer)
.faultTolerant()
.skipPolicy(new SkipPolicy())
.listener(new NewStepExecutionListener())) //This dummy listener is implementation of the StepExecutionListener
//.listener(new NewItemWrtieListener) //This dummy listener is implementation of the ItemWriteListener
.taskExecutor(taskExecutor)
.build();
return step;
}
I tried finding reason behind this but cannot understand why a change in Listener Type would require typecasting for step processing.
Can someone explain why ?