Spring Batch 6.0.0-M2 現已釋出

版本釋出 | Mahmoud Ben Hassine | 2025 年 8 月 20 日 | ...

我很高興地宣佈,Spring Batch 6.0.0-M2 現已從 Maven Central 釋出!

在此里程碑版本中,我們釋出了以下功能和改進

  • 依賴升級
  • 面向塊處理模型的新實現
  • 恢復突然失敗的作業執行的能力

有關更改的完整列表,請檢視釋出說明

依賴升級

在此里程碑版本中,Spring 依賴項已升級到以下版本

  • Spring Framework: 7.0.0-M8
  • Spring Integration: 7.0.0-M2
  • Spring AMQP: 4.0.0-M4
  • Spring Kafka: 4.0.0-M4
  • Spring Data: 4.0.0-M5
  • Spring Ldap: 4.0.0-M2
  • Micrometer: 1.16.0-M2

請注意,此版本相容 Java 17+。

面向塊處理模型的新實現

這不是一個新功能,而是面向塊處理模型的全新增強實現。這個新實現作為實驗性新增在 5.1 版本中引入,現在在 6.0 版本中作為穩定功能提供。

新實現位於 ChunkOrientedStep 類中,它替代了 ChunkOrientedTasklet / TaskletStep 類。

下面是如何使用其構建器定義 ChunkOrientedStep 的示例

@Bean
public Step chunkOrientedStep(JobRepository jobRepository, JdbcTransactionManager transactionManager,
    ItemReader<Person> itemReader, ItemProcessor<Person, Person> itemProcessor, ItemWriter<Person> itemWriter) {
    
    int chunkSize = 100;
    return new ChunkOrientedStepBuilder<Person, Person>(jobRepository, transactionManager, chunkSize)
        .reader(itemReader)
        .processor(itemProcessor)
        .writer(itemWriter)
        .build();
}

此外,容錯功能也進行了如下調整

  • 重試功能現在基於 Spring Framework 7 中引入的重試功能,而不是之前的 Spring Retry 庫
  • 跳過功能已稍微適應新實現,現在完全基於 SkipPolicy 介面

下面是如何使用新 ChunkOrientedStep 的重試和跳過功能的快速示例

@Bean
public Step faulTolerantChunkOrientedStep(JobRepository jobRepository, JdbcTransactionManager transactionManager,
    ItemReader<Person> itemReader, ItemProcessor<Person, Person> itemProcessor, ItemWriter<Person> itemWriter) {

    // retry policy configuration
    int maxAttempts = 10;
    var retrybaleExceptions = Set.of(TransientException.class);
    RetryPolicy retryPolicy = RetryPolicy.builder()
        .maxAttempts(maxAttempts)
        .includes(retrybaleExceptions)
        .build();

    // skip policy configuration
    int skipLimit = 50;
    var skippableExceptions = Set.of(FlatFileParseException.class);
    SkipPolicy skipPolicy = new LimitCheckingItemSkipPolicy(skipLimit, skippableExceptions);

    // step configuration
    int chunkSize = 100;
    return new ChunkOrientedStepBuilder<Person, Person>(jobRepository, transactionManager, chunkSize)
        .reader(itemReader)
        .processor(itemProcessor)
        .writer(itemWriter)
        .faultTolerant()
        .retryPolicy(retryPolicy)
        .skipPolicy(skipPolicy)
        .build();
}

有關如何從舊實現遷移到新實現的更多詳細資訊,請參閱遷移指南

恢復失敗的作業執行的能力

在 v6 之前,如果作業執行突然失敗,則無法在不手動更新資料庫的情況下恢復它。這容易出錯,並且在不同的作業倉庫中不一致(因為它需要一些用於 JDBC 資料庫的 SQL 語句和一些用於 NoSQL 儲存的自定義語句)。

此里程碑版本在 JobOperator 介面中引入了一個名為 recover 的新方法,允許您在所有作業倉庫中一致地恢復失敗的作業執行。

反饋

我要感謝在此版本中發揮作用的所有貢獻者!隨著我們繼續開發 Spring Batch 6,我們期待您在 Github IssuesGithub DiscussionsX 上提供反饋。


Spring Batch 主頁|Github 上的原始碼|參考文件

獲取 Spring 新聞通訊

透過 Spring 新聞通訊保持聯絡

訂閱

領先一步

VMware 提供培訓和認證,助您加速進步。

瞭解更多

獲得支援

Tanzu Spring 提供 OpenJDK™、Spring 和 Apache Tomcat® 的支援和二進位制檔案,只需一份簡單的訂閱。

瞭解更多

即將舉行的活動

檢視 Spring 社群所有即將舉行的活動。

檢視所有