【问题标题】:Compilation error when adding multiple listeners to Spring batch Step将多个侦听器添加到 Spring 批处理步骤时出现编译错误
【发布时间】:2020-02-12 17:53:20
【问题描述】:

向 Step 添加多个侦听器会导致编译错误。

    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] 找不到符号 [ERROR] 符号:方法 build() [错误]位置:类 org.springframework.batch.core.step.builder.StepBuilderHelper

如果我删除了其中一个侦听器,代码就会编译。如何将步骤侦听器和跳过侦听器添加到 Spring Batch 中的容错步骤?

使用 Spring Boot 2.1.8-RELEASE 和 Spring Batch 启动器。

<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>

【问题讨论】:

    标签: maven spring-boot spring-batch


    【解决方案1】:

    实现此目的的一种方法如下,虽然不理想,但可以。

    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();
    

    【讨论】:

      猜你喜欢
      • 2021-03-01
      • 2021-08-31
      • 1970-01-01
      • 2019-09-06
      • 1970-01-01
      • 1970-01-01
      • 2014-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多