Spring Batch 4.3.0 的第一個里程碑版本釋出了,可從里程碑倉庫獲取。
1. 新的同步 ItemStreamWriter
與 SynchronizedItemStreamReader 相似,此版本添加了 SynchronizedItemStreamWriter。此功能在多執行緒步驟中很有用,在這些步驟中,需要同步併發執行緒,以免覆蓋彼此的寫入。
2. 新增對 JpaPagingItemReader 中命名查詢的支援
JpaPagingItemReader 中可以使用命名查詢。但是,這需要建立一個自定義查詢提供程式,如下所示:
JpaPagingItemReader<Foo> reader = new JpaPagingItemReaderBuilder<Foo>() .name("fooReader") .queryProvider(new AbstractJpaQueryProvider() { @Override public Query createQuery() { return getEntityManager().createNamedQuery("allFoos", Foo.class); } @Override public void afterPropertiesSet() throws Exception { } }) // set other properties on the reader .build();
此版本引入了 JpaNamedQueryProvider 簡化配置,現在可以這樣寫:
JpaPagingItemReader<Foo> reader = new JpaPagingItemReaderBuilder<Foo>() .name("fooReader") .queryProvider(new JpaNamedQueryProvider("allFoos", Foo.class)) // set other properties on the reader .build();
3. 簡化 Spring Batch 測試的配置
與使用@ExtendWith(SpringExtension.class)
進行元註釋的 Spring Boot 測試註釋類似(例如 @SpringBootTest
, @WebMvcTest
等),新版本將@SpringBatchTest
更新為使用 @ExtendWith(SpringExtension.class)
.進行元註釋。這簡化了使用 JUnit Jupiter 編寫測試時的配置。
此功能不影響 JUnit 4 使用者,僅涉及基於 JUnit 5 的測試。
此版本還帶來不少效能改進,詳情見更新說明:
https://spring.io/blog/2020/06/26/spring-batch-4-3-0-m1-is-released-now
[admin
]