Spring Batch 4.3.0-M1 发布

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

猜你喜欢

转载自www.oschina.net/news/116757/spring-batch-4-3-0-m1-released