Reputation: 45
Adding multiple listeners to Step causes compilation error.
private Step myStep(DataSource dataSource) {
return stepBuilderFactory.get("myStep")
.<Record, Record>chunk(100)
.reader(reader)
.processor(processor)
.writer(writer)
.faultTolerant()
.listener(stepListener)
.listener(skipListener)
.build();
}
[ERROR] cannot find symbol [ERROR] symbol: method build() [ERROR] location: class org.springframework.batch.core.step.builder.StepBuilderHelper
If I removed one of the listeners, the code compiles. How do I add both step listener and skip listener to a fault tolerant step in Spring Batch?
Using Spring Boot 2.1.8-RELEASE and Spring Batch starter.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
Upvotes: 0
Views: 1514
Reputation: 45
One way to accomplish this is the following, not ideal, but it works.
SimpleStepBuilder<Record, Record> builder = stepBuilderFactory.get("myStep")
.<Record, Record>chunk(100)
.reader(reader)
.processor(processor)
.writer(writer)
.faultTolerant();
builder.listener(skipListener);
builder.listener(stepListener);
return builder.build();
Upvotes: 2